diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-06-30 10:34:30 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:36 -0400 |
commit | 40ebdb9274ba71b6211f500904a3935af81a00ca (patch) | |
tree | 691716146bcd83a2e1c1b29e020231f878fc99ac /drivers/hwmon/w83791d.c | |
parent | 7560dc0a6d45dbf0d32eb56172dd5062753a8dcc (diff) |
hwmon: (w83791d) Fix smatch warning
smatch complains as follows when checking w83791d.c.
drivers/hwmon/w83791d.c:996 store_temp23() warn:
'32768' 32768 can't fit into 32767 'data->temp_add[nr][index]'
Fix by using DIV_ROUND_CLOSEST and clamp_val to convert the values.
While we are at it, modify other macros as well for consistency and
to make the code easier to understand.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/w83791d.c')
-rw-r--r-- | drivers/hwmon/w83791d.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index bdcf2dce5ec4..cb3765fec98c 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -249,19 +249,16 @@ static u8 fan_to_reg(long rpm, int div) | |||
249 | * the bottom 7 bits will always be zero | 249 | * the bottom 7 bits will always be zero |
250 | */ | 250 | */ |
251 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) | 251 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) |
252 | #define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 252 | #define TEMP23_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ |
253 | (val) >= 127500 ? 0x7F80 : \ | 253 | 127500), 500) * 128) |
254 | (val) < 0 ? ((val) - 250) / 500 * 128 : \ | ||
255 | ((val) + 250) / 500 * 128) | ||
256 | 254 | ||
257 | /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */ | 255 | /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */ |
258 | #define TARGET_TEMP_TO_REG(val) ((val) < 0 ? 0 : \ | 256 | #define TARGET_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 127000), \ |
259 | (val) >= 127000 ? 127 : \ | 257 | 1000) |
260 | ((val) + 500) / 1000) | ||
261 | 258 | ||
262 | /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */ | 259 | /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */ |
263 | #define TOL_TEMP_TO_REG(val) ((val) >= 15000 ? 15 : \ | 260 | #define TOL_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 15000), \ |
264 | ((val) + 500) / 1000) | 261 | 1000) |
265 | 262 | ||
266 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) | 263 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) |
267 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) | 264 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) |