From: Guenter Roeck <linux@roeck-us.net>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] hwmon: (adm1031) Fix writes to limit registers
Date: Mon, 07 Jul 2014 12:55:56 +0000 [thread overview]
Message-ID: <53BA98DC.6010300@roeck-us.net> (raw)
In-Reply-To: <1404421019-16103-1-git-send-email-linux@roeck-us.net>
Hi Jean,
On 07/07/2014 12:10 AM, Jean Delvare wrote:
> Hi Guenter,
>
> On Thu, 3 Jul 2014 13:56:59 -0700, Guenter Roeck wrote:
>> Upper limit for write operations to temperature limit registers
>> was clamped to a fractional value. However, limit registers do
>> not support fractional values. As a result, upper limits of 127.5
>> degrees C or higher resulted in a rounded limit of 128 degrees C.
>> Since limit registers are signed, this was stored as -128 degrees C.
>> Clamp limits to (-55, +127) degrees C to solve the problem.
>
> Good catch, sorry for missing this bug during my original review.
>
Easy to miss without explicit module test, really. I bet we have a
lot of similar problems in other drivers ;-).
>> Value on writes to auto_temp[12]_min and auto_temp[12]_max were not
>> clamped at all, but masked. As a result, out-of-range writes resulted
>> in a more or less arbitrary limit. Clamp those attributes to (0, 127)
>> degrees C for more predictable results.
>
> Ditto.
>
>> Cc: Axel Lin <axel.lin@ingics.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> drivers/hwmon/adm1031.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
>> index a8a540c..9eaa235 100644
>> --- a/drivers/hwmon/adm1031.c
>> +++ b/drivers/hwmon/adm1031.c
>> @@ -366,6 +366,7 @@ set_auto_temp_min(struct device *dev, struct device_attribute *attr,
>> return ret;
>>
>> mutex_lock(&data->update_lock);
>> + val = clamp_val(val, 0, 127000);
>
> For consistency and performance, please clamp the value before locking
> the mutex.
>
>> data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
>> adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
>> data->auto_temp[nr]);
>> @@ -395,6 +396,7 @@ set_auto_temp_max(struct device *dev, struct device_attribute *attr,
>> return ret;
>>
>> mutex_lock(&data->update_lock);
>> + val = clamp_val(val, 0, 127000);
>
> Same here.
>
Ok, done.
>> data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr],
>> data->pwm[nr]);
>> adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
>> @@ -696,7 +698,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
>> if (ret)
>> return ret;
>>
>> - val = clamp_val(val, -55000, nr = 0 ? 127750 : 127875);
>> + val = clamp_val(val, -55000, 127000);
>> mutex_lock(&data->update_lock);
>> data->temp_min[nr] = TEMP_TO_REG(val);
>> adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
>> @@ -717,7 +719,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
>> if (ret)
>> return ret;
>>
>> - val = clamp_val(val, -55000, nr = 0 ? 127750 : 127875);
>> + val = clamp_val(val, -55000, 127000);
>> mutex_lock(&data->update_lock);
>> data->temp_max[nr] = TEMP_TO_REG(val);
>> adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
>> @@ -738,7 +740,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
>> if (ret)
>> return ret;
>>
>> - val = clamp_val(val, -55000, nr = 0 ? 127750 : 127875);
>> + val = clamp_val(val, -55000, 127000);
>> mutex_lock(&data->update_lock);
>> data->temp_crit[nr] = TEMP_TO_REG(val);
>> adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
>
> Reviewed-by: Jean Delvare <jdelvare@suse.de>
>
Thanks!
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
prev parent reply other threads:[~2014-07-07 12:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-03 20:56 [lm-sensors] [PATCH] hwmon: (adm1031) Fix writes to limit registers Guenter Roeck
2014-07-07 7:10 ` Jean Delvare
2014-07-07 12:55 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53BA98DC.6010300@roeck-us.net \
--to=linux@roeck-us.net \
--cc=lm-sensors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.