mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
hwmon: (max6697) Fix underflow when writing limit attributes
[ Upstream commit cbf7467828cd4ec7ceac7a8b5b5ddb2f69f07b0e ]
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: 5372d2d71c ("hwmon: Driver for Maxim MAX6697 and compatibles")
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
6afaf55a14
commit
2c15d26759
@@ -312,6 +312,7 @@ static ssize_t temp_store(struct device *dev,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
|
temp = clamp_val(temp, -1000000, 1000000); /* prevent underflow */
|
||||||
temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset;
|
temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset;
|
||||||
temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127);
|
temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127);
|
||||||
data->temp[nr][index] = temp;
|
data->temp[nr][index] = temp;
|
||||||
|
|||||||
Reference in New Issue
Block a user