From: Guenter Roeck Date: Sat, 13 Jul 2024 21:26:19 +0000 (-0700) Subject: hwmon: (max6697) Fix underflow when writing limit attributes X-Git-Tag: io_uring-6.11-20240722~120^2~1 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=cbf7467828cd4ec7ceac7a8b5b5ddb2f69f07b0e;p=linux-2.6-block.git 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: 5372d2d71c46 ("hwmon: Driver for Maxim MAX6697 and compatibles") Reviewed-by: Tzung-Bi Shih Signed-off-by: Guenter Roeck --- diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c index b28b7b9448aa..05085646ba99 100644 --- a/drivers/hwmon/max6697.c +++ b/drivers/hwmon/max6697.c @@ -311,6 +311,7 @@ static ssize_t temp_store(struct device *dev, return ret; mutex_lock(&data->update_lock); + temp = clamp_val(temp, -1000000, 1000000); /* prevent underflow */ temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); data->temp[nr][index] = temp;