Skip to content

Commit af64e3e

Browse files
committed
hwmon: (lm95234) Fix underflows seen when writing limit attributes
DIV_ROUND_CLOSEST() after kstrtol() results in an underflow if a large negative number such as -9223372036854775808 is provided by the user. Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations. Signed-off-by: Guenter Roeck <[email protected]>
1 parent 8cad724 commit af64e3e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/hwmon/lm95234.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr,
301301
if (ret < 0)
302302
return ret;
303303

304-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, index ? 255 : 127);
304+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, (index ? 255 : 127) * 1000),
305+
1000);
305306

306307
mutex_lock(&data->update_lock);
307308
data->tcrit2[index] = val;
@@ -350,7 +351,7 @@ static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr,
350351
if (ret < 0)
351352
return ret;
352353

353-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 255);
354+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000);
354355

355356
mutex_lock(&data->update_lock);
356357
data->tcrit1[index] = val;
@@ -391,7 +392,7 @@ static ssize_t tcrit1_hyst_store(struct device *dev,
391392
if (ret < 0)
392393
return ret;
393394

394-
val = DIV_ROUND_CLOSEST(val, 1000);
395+
val = DIV_ROUND_CLOSEST(clamp_val(val, -255000, 255000), 1000);
395396
val = clamp_val((int)data->tcrit1[index] - val, 0, 31);
396397

397398
mutex_lock(&data->update_lock);
@@ -431,7 +432,7 @@ static ssize_t offset_store(struct device *dev, struct device_attribute *attr,
431432
return ret;
432433

433434
/* Accuracy is 1/2 degrees C */
434-
val = clamp_val(DIV_ROUND_CLOSEST(val, 500), -128, 127);
435+
val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500);
435436

436437
mutex_lock(&data->update_lock);
437438
data->toffset[index] = val;

0 commit comments

Comments
 (0)