Skip to content

Commit 5c1de37

Browse files
committed
hwmon: (w83627ehf) 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 0403e10 commit 5c1de37

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/hwmon/w83627ehf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr,
895895
if (err < 0)
896896
return err;
897897

898-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 127);
898+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000);
899899

900900
mutex_lock(&data->update_lock);
901901
data->target_temp[nr] = val;
@@ -920,7 +920,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
920920
return err;
921921

922922
/* Limit the temp to 0C - 15C */
923-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15);
923+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 15000), 1000);
924924

925925
mutex_lock(&data->update_lock);
926926
reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);

0 commit comments

Comments
 (0)