Skip to content

Commit 7953605

Browse files
SpieringsAEgroeck
authored andcommitted
hwmon: (ntc_thermistor) return error instead of clipping on OOB
When the ntc is reading Out Of Bounds instead of clipping to the nearest limit (min/max) return -ENODATA. This prevents malfunctioning sensors from sending a device into a shutdown loop due to a critical trip. This implementation will only work for ntc type thermistors if a ptc type is to be implemented the min/max ohm calculation must be adjusted to take that into account. Signed-off-by: Maud Spierings <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent ee65d9e commit 7953605

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/hwmon/ntc_thermistor.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,9 @@ static int get_ohm_of_thermistor(struct ntc_data *data, unsigned int uv)
387387
puo = data->pullup_ohm;
388388
pdo = data->pulldown_ohm;
389389

390-
if (uv == 0)
391-
return (data->connect == NTC_CONNECTED_POSITIVE) ?
392-
INT_MAX : 0;
393-
if (uv >= puv)
394-
return (data->connect == NTC_CONNECTED_POSITIVE) ?
395-
0 : INT_MAX;
390+
/* faulty adc value */
391+
if (uv == 0 || uv >= puv)
392+
return -ENODATA;
396393

397394
if (data->connect == NTC_CONNECTED_POSITIVE && puo == 0)
398395
n = div_u64(pdo * (puv - uv), uv);
@@ -404,8 +401,10 @@ static int get_ohm_of_thermistor(struct ntc_data *data, unsigned int uv)
404401
else
405402
n = div64_u64_safe(pdo * puo * uv, pdo * (puv - uv) - puo * uv);
406403

407-
if (n > INT_MAX)
408-
n = INT_MAX;
404+
/* sensor out of bounds */
405+
if (n > data->comp[0].ohm || n < data->comp[data->n_comp - 1].ohm)
406+
return -ENODATA;
407+
409408
return n;
410409
}
411410

0 commit comments

Comments
 (0)