diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-07-30 01:23:12 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-07-31 00:42:33 -0400 |
commit | 3248c3b771ddd9d31695da17ba350eb6e1b80a53 (patch) | |
tree | e6457d08a935abcf10ea9d4d3be2251f21bde002 /drivers/hwmon/lm85.c | |
parent | 56de1377ad92f72ee4e5cb0faf7a9b6048fdf0bf (diff) |
hwmon: (lm85) Fix various errors on attribute writes
Temperature limit register writes did not account for negative numbers.
As a result, writing -127000 resulted in -126000 written into the
temperature limit register. This problem affected temp[1-3]_min,
temp[1-3]_max, temp[1-3]_auto_temp_crit, and temp[1-3]_auto_temp_min.
When writing pwm[1-3]_freq, a long variable was auto-converted into an int
without range check. Wiring values larger than MAXINT resulted in unexpected
register values.
When writing temp[1-3]_auto_temp_max, an unsigned long variable was
auto-converted into an int without range check. Writing values larger than
MAXINT resulted in unexpected register values.
vrm is an u8, so the written value needs to be limited to [0, 255].
Cc: Axel Lin <axel.lin@ingics.com>
Cc: stable@vger.kernel.org
Reviewed-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r-- | drivers/hwmon/lm85.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index b0129a54e1a6..ef627ea71cc8 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -155,7 +155,7 @@ static inline u16 FAN_TO_REG(unsigned long val) | |||
155 | 155 | ||
156 | /* Temperature is reported in .001 degC increments */ | 156 | /* Temperature is reported in .001 degC increments */ |
157 | #define TEMP_TO_REG(val) \ | 157 | #define TEMP_TO_REG(val) \ |
158 | clamp_val(SCALE(val, 1000, 1), -127, 127) | 158 | DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000) |
159 | #define TEMPEXT_FROM_REG(val, ext) \ | 159 | #define TEMPEXT_FROM_REG(val, ext) \ |
160 | SCALE(((val) << 4) + (ext), 16, 1000) | 160 | SCALE(((val) << 4) + (ext), 16, 1000) |
161 | #define TEMP_FROM_REG(val) ((val) * 1000) | 161 | #define TEMP_FROM_REG(val) ((val) * 1000) |
@@ -189,7 +189,7 @@ static const int lm85_range_map[] = { | |||
189 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 | 189 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
190 | }; | 190 | }; |
191 | 191 | ||
192 | static int RANGE_TO_REG(int range) | 192 | static int RANGE_TO_REG(long range) |
193 | { | 193 | { |
194 | int i; | 194 | int i; |
195 | 195 | ||
@@ -211,7 +211,7 @@ static const int adm1027_freq_map[8] = { /* 1 Hz */ | |||
211 | 11, 15, 22, 29, 35, 44, 59, 88 | 211 | 11, 15, 22, 29, 35, 44, 59, 88 |
212 | }; | 212 | }; |
213 | 213 | ||
214 | static int FREQ_TO_REG(const int *map, int freq) | 214 | static int FREQ_TO_REG(const int *map, unsigned long freq) |
215 | { | 215 | { |
216 | int i; | 216 | int i; |
217 | 217 | ||
@@ -460,6 +460,9 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, | |||
460 | if (err) | 460 | if (err) |
461 | return err; | 461 | return err; |
462 | 462 | ||
463 | if (val > 255) | ||
464 | return -EINVAL; | ||
465 | |||
463 | data->vrm = val; | 466 | data->vrm = val; |
464 | return count; | 467 | return count; |
465 | } | 468 | } |