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:
Tom Deconinck 2025-06-02 16:12:06 +02:00 committed by Benjamin Cabé
commit e25147647c

View file

@ -69,8 +69,10 @@ static int ntc_thermistor_channel_get(const struct device *dev, enum sensor_chan
switch (chan) { switch (chan) {
case SENSOR_CHAN_AMBIENT_TEMP: case SENSOR_CHAN_AMBIENT_TEMP:
k_mutex_lock(&data->mutex, K_FOREVER);
ohm = ntc_get_ohm_of_thermistor(&cfg->ntc_cfg, data->sample_val, ohm = ntc_get_ohm_of_thermistor(&cfg->ntc_cfg, data->sample_val,
data->sample_val_max); data->sample_val_max);
k_mutex_unlock(&data->mutex);
temp = ntc_get_temp_mc(&cfg->ntc_cfg.type, ohm); temp = ntc_get_temp_mc(&cfg->ntc_cfg.type, ohm);
val->val1 = temp / 1000; val->val1 = temp / 1000;
val->val2 = (temp % 1000) * 1000; val->val2 = (temp % 1000) * 1000;