Commit 40ebdb92 authored by Guenter Roeck's avatar Guenter Roeck

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: default avatarGuenter Roeck <linux@roeck-us.net>
parent 7560dc0a
...@@ -249,19 +249,16 @@ static u8 fan_to_reg(long rpm, int div) ...@@ -249,19 +249,16 @@ static u8 fan_to_reg(long rpm, int div)
* the bottom 7 bits will always be zero * the bottom 7 bits will always be zero
*/ */
#define TEMP23_FROM_REG(val) ((val) / 128 * 500) #define TEMP23_FROM_REG(val) ((val) / 128 * 500)
#define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ #define TEMP23_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \
(val) >= 127500 ? 0x7F80 : \ 127500), 500) * 128)
(val) < 0 ? ((val) - 250) / 500 * 128 : \
((val) + 250) / 500 * 128)
/* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */ /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */
#define TARGET_TEMP_TO_REG(val) ((val) < 0 ? 0 : \ #define TARGET_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 127000), \
(val) >= 127000 ? 127 : \ 1000)
((val) + 500) / 1000)
/* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */ /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */
#define TOL_TEMP_TO_REG(val) ((val) >= 15000 ? 15 : \ #define TOL_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 15000), \
((val) + 500) / 1000) 1000)
#define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff)
#define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff)
......
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