Skip to content

Commit 57ee12b

Browse files
Pei Xiaogroeck
authored andcommitted
hwmon: (nct6775-core) Fix overflows seen when writing limit attributes
DIV_ROUND_CLOSEST() after kstrtoul() results in an overflow if a large number such as 18446744073709551615 is provided by the user. Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations. Signed-off-by: Pei Xiao <[email protected]> Fixes: c3963bc ("hwmon: (nct6775) Split core and platform driver") Message-ID: <7d5084cea33f7c0fd0578c59adfff71f93de94d9.1731375425.git.xiaopei01@kylinos.cn> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 255ab27 commit 57ee12b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/hwmon/nct6775-core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,8 +2878,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr,
28782878
if (err < 0)
28792879
return err;
28802880

2881-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0,
2882-
data->target_temp_mask);
2881+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, data->target_temp_mask * 1000), 1000);
28832882

28842883
mutex_lock(&data->update_lock);
28852884
data->target_temp[nr] = val;
@@ -2959,7 +2958,7 @@ store_temp_tolerance(struct device *dev, struct device_attribute *attr,
29592958
return err;
29602959

29612960
/* Limit tolerance as needed */
2962-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, data->tolerance_mask);
2961+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, data->tolerance_mask * 1000), 1000);
29632962

29642963
mutex_lock(&data->update_lock);
29652964
data->temp_tolerance[index][nr] = val;
@@ -3085,7 +3084,7 @@ store_weight_temp(struct device *dev, struct device_attribute *attr,
30853084
if (err < 0)
30863085
return err;
30873086

3088-
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 255);
3087+
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000);
30893088

30903089
mutex_lock(&data->update_lock);
30913090
data->weight_temp[index][nr] = val;

0 commit comments

Comments
 (0)