diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-06-25 19:08:35 +0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 18:01:36 +0400 |
commit | 7560dc0a6d45dbf0d32eb56172dd5062753a8dcc (patch) | |
tree | d634a14d17c21714da9d168fc3311f04dee58514 /drivers/hwmon/lm63.c | |
parent | 034b44b4a22371c5bcbfb602a5420f3b75939dd8 (diff) | |
download | linux-7560dc0a6d45dbf0d32eb56172dd5062753a8dcc.tar.xz |
hwmon: (lm63) Fix smatch warnings
smatch complains as follows when checking lm63.c.
drivers/hwmon/lm63.c:594 set_temp11() warn:
'65504' 65504 can't fit into 32767 'data->temp11[nr]'
drivers/hwmon/lm63.c:596 set_temp11() warn:
'32768' 32768 can't fit into 32767 'data->temp11[nr]'
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/lm63.c')
-rw-r--r-- | drivers/hwmon/lm63.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 848b9611151f..33bfdb444138 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c @@ -126,24 +126,17 @@ static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ (5400000 / (val)) & 0xFFFC) #define TEMP8_FROM_REG(reg) ((reg) * 1000) -#define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ - (val) >= 127000 ? 127 : \ - (val) < 0 ? ((val) - 500) / 1000 : \ - ((val) + 500) / 1000) -#define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ - (val) >= 255000 ? 255 : \ - ((val) + 500) / 1000) +#define TEMP8_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ + 127000), 1000) +#define TEMP8U_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, \ + 255000), 1000) #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) -#define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ - (val) >= 127875 ? 0x7FE0 : \ - (val) < 0 ? ((val) - 62) / 125 * 32 : \ - ((val) + 62) / 125 * 32) -#define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ - (val) >= 255875 ? 0xFFE0 : \ - ((val) + 62) / 125 * 32) -#define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ - (val) >= 127000 ? 127 : \ - ((val) + 500) / 1000) +#define TEMP11_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ + 127875), 125) * 32) +#define TEMP11U_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), 0, \ + 255875), 125) * 32) +#define HYST_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 127000), \ + 1000) #define UPDATE_INTERVAL(max, rate) \ ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) |