]> git.hungrycats.org Git - linux/commit
hwmon: (lm92) Prevent overflow problem when writing large limits
authorAxel Lin <axel.lin@ingics.com>
Tue, 5 Aug 2014 02:08:31 +0000 (10:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Sep 2014 23:36:30 +0000 (16:36 -0700)
commit99348bdedca59b84ab42db96377880e72450f2b5
treee2998a0838ffdcf632ac332fd20e7b9bfc092940
parent26a05f267c31903055b5a54fc88bcd5ef711da73
hwmon: (lm92) Prevent overflow problem when writing large limits

commit 5b963089161b8fb244889c972edf553b9d737545 upstream.

On platforms with sizeof(int) < sizeof(long), writing a temperature
limit larger than MAXINT will result in unpredictable limit values
written to the chip. Avoid auto-conversion from long to int to fix
the problem.

The hysteresis temperature range depends on the value of
data->temp[attr->index], since val is subtracted from it.
Use a wider clamp, [-120000, 220000] should do to cover the
possible range. Also add missing TEMP_TO_REG() on writes into
cached hysteresis value.

Also uses clamp_val to simplify the code a bit.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
[Guenter Roeck: Fixed double TEMP_TO_REG on hysteresis updates]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwmon/lm92.c