Skip to content

Commit e251476

Browse files
tdeco80kartben
authored andcommitted
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>
1 parent 47d1e38 commit e251476

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/sensor/ntc_thermistor/ntc_thermistor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ static int ntc_thermistor_channel_get(const struct device *dev, enum sensor_chan
6969

7070
switch (chan) {
7171
case SENSOR_CHAN_AMBIENT_TEMP:
72+
k_mutex_lock(&data->mutex, K_FOREVER);
7273
ohm = ntc_get_ohm_of_thermistor(&cfg->ntc_cfg, data->sample_val,
7374
data->sample_val_max);
75+
k_mutex_unlock(&data->mutex);
7476
temp = ntc_get_temp_mc(&cfg->ntc_cfg.type, ohm);
7577
val->val1 = temp / 1000;
7678
val->val2 = (temp % 1000) * 1000;

0 commit comments

Comments
 (0)