mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-07 09:55:19 +02:00
hwmon: (max16065) Fix overflows seen when writing limits
[ Upstream commit744ec4477b
] Writing large limits resulted in overflows as reported by module tests. in0_lcrit: Suspected overflow: [max=5538, read 0, written 2147483647] in0_crit: Suspected overflow: [max=5538, read 0, written 2147483647] in0_min: Suspected overflow: [max=5538, read 0, written 2147483647] Fix the problem by clamping prior to multiplications and the use of DIV_ROUND_CLOSEST, and by using consistent variable types. Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Fixes:f5bae2642e
("hwmon: Driver for MAX16065 System Manager and compatibles") Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
f606b9ac4a
commit
0c7af15f64
|
@ -114,9 +114,10 @@ static inline int LIMIT_TO_MV(int limit, int range)
|
||||||
return limit * range / 256;
|
return limit * range / 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MV_TO_LIMIT(int mv, int range)
|
static inline int MV_TO_LIMIT(unsigned long mv, int range)
|
||||||
{
|
{
|
||||||
return clamp_val(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255);
|
mv = clamp_val(mv, 0, ULONG_MAX / 256);
|
||||||
|
return DIV_ROUND_CLOSEST(clamp_val(mv * 256, 0, range * 255), range);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ADC_TO_CURR(int adc, int gain)
|
static inline int ADC_TO_CURR(int adc, int gain)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user