Skip to content

Commit

Permalink
hwmon: (lm85) Fix overflows seen when writing voltage limit attributes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Guenter Roeck committed Dec 12, 2016
1 parent 12fa55c commit 67b2003
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/hwmon/lm85.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 67b2003

Please sign in to comment.