Skip to content

Commit cbf7467

Browse files
committed
hwmon: (max6697) Fix underflow when writing limit attributes
Using DIV_ROUND_CLOSEST() on an unbound value can result in underflows. Indeed, module test scripts report: temp1_max: Suspected underflow: [min=0, read 255000, written -9223372036854775808] temp1_crit: Suspected underflow: [min=0, read 255000, written -9223372036854775808] Fix by introducing an extra set of clamping. Fixes: 5372d2d ("hwmon: Driver for Maxim MAX6697 and compatibles") Reviewed-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent ed99ae7 commit cbf7467

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/hwmon/max6697.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ static ssize_t temp_store(struct device *dev,
311311
return ret;
312312

313313
mutex_lock(&data->update_lock);
314+
temp = clamp_val(temp, -1000000, 1000000); /* prevent underflow */
314315
temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset;
315316
temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127);
316317
data->temp[nr][index] = temp;

0 commit comments

Comments
 (0)