Commit 67b20034 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (lm85) Fix overflows seen when writing voltage limit attributes

Writes into voltage limit attributes can overflow due to an unbound
multiplication.
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 12fa55cc
......@@ -136,7 +136,8 @@ static const int lm85_scaling[] = { /* .001 Volts */
#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
#define INS_TO_REG(n, val) \
clamp_val(SCALE(val, lm85_scaling[n], 192), 0, 255)
SCALE(clamp_val(val, 0, 255 * lm85_scaling[n] / 192), \
lm85_scaling[n], 192)
#define INSEXT_FROM_REG(n, val, ext) \
SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment