aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2016-12-04 21:16:48 -0500
committerGuenter Roeck <linux@roeck-us.net>2016-12-12 14:33:43 -0500
commit67b2003485ee48dcfcb5338171defa4093bba02e (patch)
tree20c77fcbdf51360025df77bad3b22dc47690d729
parent12fa55ccc49df52617d7454ba448c1876e189bac (diff)
hwmon: (lm85) Fix overflows seen when writing voltage limit attributes
Writes into voltage limit attributes can overflow due to an unbound multiplication. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/lm85.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 6ff773fcaefb..29c8136ce9c5 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -136,7 +136,8 @@ static const int lm85_scaling[] = { /* .001 Volts */
136#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) 136#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
137 137
138#define INS_TO_REG(n, val) \ 138#define INS_TO_REG(n, val) \
139 clamp_val(SCALE(val, lm85_scaling[n], 192), 0, 255) 139 SCALE(clamp_val(val, 0, 255 * lm85_scaling[n] / 192), \
140 lm85_scaling[n], 192)
140 141
141#define INSEXT_FROM_REG(n, val, ext) \ 142#define INSEXT_FROM_REG(n, val, ext) \
142 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) 143 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])