mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-06 17:35:20 +02:00
hwmon: (lm95234) Fix underflows seen when writing limit attributes
[ Upstream commit af64e3e153
]
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 <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
6891b11a0c
commit
46e4fd338d
|
@ -301,7 +301,8 @@ static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, index ? 255 : 127);
|
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, (index ? 255 : 127) * 1000),
|
||||||
|
1000);
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
data->tcrit2[index] = val;
|
data->tcrit2[index] = val;
|
||||||
|
@ -350,7 +351,7 @@ static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 255);
|
val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000);
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
data->tcrit1[index] = val;
|
data->tcrit1[index] = val;
|
||||||
|
@ -391,7 +392,7 @@ static ssize_t tcrit1_hyst_store(struct device *dev,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
val = DIV_ROUND_CLOSEST(val, 1000);
|
val = DIV_ROUND_CLOSEST(clamp_val(val, -255000, 255000), 1000);
|
||||||
val = clamp_val((int)data->tcrit1[index] - val, 0, 31);
|
val = clamp_val((int)data->tcrit1[index] - val, 0, 31);
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
|
@ -431,7 +432,7 @@ static ssize_t offset_store(struct device *dev, struct device_attribute *attr,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Accuracy is 1/2 degrees C */
|
/* Accuracy is 1/2 degrees C */
|
||||||
val = clamp_val(DIV_ROUND_CLOSEST(val, 500), -128, 127);
|
val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500);
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
data->toffset[index] = val;
|
data->toffset[index] = val;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user