* [PATCH v2] hwmon: (adt7462) Fix overflows seen when writing into limit attributes
@ 2016-12-08 19:26 Guenter Roeck
2016-12-09 9:29 ` Jean Delvare
0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2016-12-08 19:26 UTC (permalink / raw)
To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck
Fix overflows seen when writing large values into temperature limit,
voltage limit, and pwm hysteresis attributes.
The input parameter to DIV_ROUND_CLOSEST() needs to be clamped to avoid
such overflows.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Simplified clamping
Separate clamp_val() and DIV_ROUND_CLOSEST() into two lines.
drivers/hwmon/adt7462.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
index 5929e126da63..19f2a6d48bac 100644
--- a/drivers/hwmon/adt7462.c
+++ b/drivers/hwmon/adt7462.c
@@ -810,8 +810,8 @@ static ssize_t set_temp_min(struct device *dev,
if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
return -EINVAL;
+ temp = clamp_val(temp, -64000, 191000);
temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
- temp = clamp_val(temp, 0, 255);
mutex_lock(&data->lock);
data->temp_min[attr->index] = temp;
@@ -848,8 +848,8 @@ static ssize_t set_temp_max(struct device *dev,
if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
return -EINVAL;
+ temp = clamp_val(temp, -64000, 191000);
temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
- temp = clamp_val(temp, 0, 255);
mutex_lock(&data->lock);
data->temp_max[attr->index] = temp;
@@ -912,9 +912,9 @@ static ssize_t set_volt_max(struct device *dev,
if (kstrtol(buf, 10, &temp) || !x)
return -EINVAL;
+ temp = clamp_val(temp, 0, 255 * x / 1000);
temp *= 1000; /* convert mV to uV */
temp = DIV_ROUND_CLOSEST(temp, x);
- temp = clamp_val(temp, 0, 255);
mutex_lock(&data->lock);
data->volt_max[attr->index] = temp;
@@ -954,9 +954,9 @@ static ssize_t set_volt_min(struct device *dev,
if (kstrtol(buf, 10, &temp) || !x)
return -EINVAL;
+ temp = clamp_val(temp, 0, 255 * x / 1000);
temp *= 1000; /* convert mV to uV */
temp = DIV_ROUND_CLOSEST(temp, x);
- temp = clamp_val(temp, 0, 255);
mutex_lock(&data->lock);
data->volt_min[attr->index] = temp;
@@ -1220,8 +1220,8 @@ static ssize_t set_pwm_hyst(struct device *dev,
if (kstrtol(buf, 10, &temp))
return -EINVAL;
+ temp = clamp_val(temp, 0, 15000);
temp = DIV_ROUND_CLOSEST(temp, 1000);
- temp = clamp_val(temp, 0, 15);
/* package things up */
temp &= ADT7462_PWM_HYST_MASK;
@@ -1306,8 +1306,8 @@ static ssize_t set_pwm_tmin(struct device *dev,
if (kstrtol(buf, 10, &temp))
return -EINVAL;
+ temp = clamp_val(temp, -64000, 191000);
temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
- temp = clamp_val(temp, 0, 255);
mutex_lock(&data->lock);
data->pwm_tmin[attr->index] = temp;
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] hwmon: (adt7462) Fix overflows seen when writing into limit attributes
2016-12-08 19:26 [PATCH v2] hwmon: (adt7462) Fix overflows seen when writing into limit attributes Guenter Roeck
@ 2016-12-09 9:29 ` Jean Delvare
0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2016-12-09 9:29 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Hardware Monitoring
On Thu, 8 Dec 2016 11:26:49 -0800, Guenter Roeck wrote:
> Fix overflows seen when writing large values into temperature limit,
> voltage limit, and pwm hysteresis attributes.
>
> The input parameter to DIV_ROUND_CLOSEST() needs to be clamped to avoid
> such overflows.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2: Simplified clamping
> Separate clamp_val() and DIV_ROUND_CLOSEST() into two lines.
>
> drivers/hwmon/adt7462.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
> (...)
Reviewed-by: Jean Delvare <jdelvare@suse.de>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-09 9:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-08 19:26 [PATCH v2] hwmon: (adt7462) Fix overflows seen when writing into limit attributes Guenter Roeck
2016-12-09 9:29 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox