diff options
author | Guenter Roeck <linux@roeck-us.net> | 2016-12-27 17:15:06 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2017-01-10 11:58:36 -0500 |
commit | f80e868cb92aa68b775c1aee434b440475f62d61 (patch) | |
tree | ae837eb3fe1fa2699d8b6e54daf592c995323610 /drivers/hwmon/gl518sm.c | |
parent | 07cc189d160ba962c5d9078453929ffac0e739f3 (diff) |
hwmon: (gl518sm) Fix overflows seen when writing into limit attributes
Writes into limit attributes can overflow due to additions and
multiplications with unchecked parameters.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/gl518sm.c')
-rw-r--r-- | drivers/hwmon/gl518sm.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 0212c8317bca..b267510daeb2 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -86,9 +86,8 @@ enum chips { gl518sm_r00, gl518sm_r80 }; | |||
86 | #define BOOL_FROM_REG(val) ((val) ? 0 : 1) | 86 | #define BOOL_FROM_REG(val) ((val) ? 0 : 1) |
87 | #define BOOL_TO_REG(val) ((val) ? 0 : 1) | 87 | #define BOOL_TO_REG(val) ((val) ? 0 : 1) |
88 | 88 | ||
89 | #define TEMP_TO_REG(val) clamp_val(((((val) < 0 ? \ | 89 | #define TEMP_CLAMP(val) clamp_val(val, -119000, 136000) |
90 | (val) - 500 : \ | 90 | #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 119) |
91 | (val) + 500) / 1000) + 119), 0, 255) | ||
92 | #define TEMP_FROM_REG(val) (((val) - 119) * 1000) | 91 | #define TEMP_FROM_REG(val) (((val) - 119) * 1000) |
93 | 92 | ||
94 | static inline u8 FAN_TO_REG(long rpm, int div) | 93 | static inline u8 FAN_TO_REG(long rpm, int div) |
@@ -101,11 +100,13 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
101 | } | 100 | } |
102 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div)))) | 101 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div)))) |
103 | 102 | ||
104 | #define IN_TO_REG(val) clamp_val((((val) + 9) / 19), 0, 255) | 103 | #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19) |
104 | #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19) | ||
105 | #define IN_FROM_REG(val) ((val) * 19) | 105 | #define IN_FROM_REG(val) ((val) * 19) |
106 | 106 | ||
107 | #define VDD_TO_REG(val) clamp_val((((val) * 4 + 47) / 95), 0, 255) | 107 | #define VDD_CLAMP(val) clamp_val(val, 0, 255 * 95 / 4) |
108 | #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4) | 108 | #define VDD_TO_REG(val) DIV_ROUND_CLOSEST(VDD_CLAMP(val) * 4, 95) |
109 | #define VDD_FROM_REG(val) DIV_ROUND_CLOSEST((val) * 95, 4) | ||
109 | 110 | ||
110 | #define DIV_FROM_REG(val) (1 << (val)) | 111 | #define DIV_FROM_REG(val) (1 << (val)) |
111 | 112 | ||