drivers: sensor: ntc-thermistor-generic: add missing mutex
The ntc-thermistor-generic is not thread safe when calling sensor_channel_get() due to the mutex not being used in ntc_thermistor_channel_get() when the sampled data is accessed. Add the thermistor_data mutex around the data access to fix. Signed-off-by: Tom Deconinck <t.deconinck@gmail.com>
This commit is contained in:
parent
47d1e38043
commit
e25147647c
1 changed files with 2 additions and 0 deletions
|
@ -69,8 +69,10 @@ static int ntc_thermistor_channel_get(const struct device *dev, enum sensor_chan
|
|||
|
||||
switch (chan) {
|
||||
case SENSOR_CHAN_AMBIENT_TEMP:
|
||||
k_mutex_lock(&data->mutex, K_FOREVER);
|
||||
ohm = ntc_get_ohm_of_thermistor(&cfg->ntc_cfg, data->sample_val,
|
||||
data->sample_val_max);
|
||||
k_mutex_unlock(&data->mutex);
|
||||
temp = ntc_get_temp_mc(&cfg->ntc_cfg.type, ohm);
|
||||
val->val1 = temp / 1000;
|
||||
val->val2 = (temp % 1000) * 1000;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue