power: supply: ip5xxx: Fix integer overflow in current_now calculation
Subsystems (3)
PATCH 1/1 power: supply: ip5xxx: Fix integer overflow in current_now calculation
When current is larger than ~2A, the multiplication in current_now property overflows and the kernel reports invalid negative current value. Change the numerator and denominator while preserving their ratio to allow up to +-6A before the overflow.
--- drivers/power/supply/ip5xxx_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/ip5xxx_power.c +1 -1
@@ -398,7 +398,7 @@ static int ip5xxx_battery_get_property(struct power_supply *psy, ret =ip5xxx_battery_read_adc (ip5xxx,IP5XXX_BATIADC_DAT0 ,IP5XXX_BATIADC_DAT1 , &raw); - val->intval =DIV_ROUND_CLOSEST (raw *745985 ,1000 ); + val->intval =DIV_ROUND_CLOSEST (raw *261095 ,350 );return 0 ;case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
Signature · 1 line
2.38.1
Quoted 7 lines · Ondrej Jirman
When current is larger than ~2A, the multiplication in
current_nowproperty overflows and the kernel reports invalid negative current value. Change the numerator and denominator while preserving their ratio to allow up to +-6A before the overflow.Fixes 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")Signed-off-by Ondrej Jirman <[email protected]>
Quoted 9 lines
--- drivers/power/supply/ip5xxx_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/ip5xxx_power.c +0
-0
drivers/power/supply/ip5xxx_power.c static int ip5xxx_battery_get_property(struct power_supply *psy, · line 401
Quoted 5 lines
drivers/power/supply/ip5xxx_power.c +1
-1@@ -398,7 +398,7 @@ static int ip5xxx_battery_get_property(struct power_supply *psy, ret =ip5xxx_battery_read_adc (ip5xxx,IP5XXX_BATIADC_DAT0 ,IP5XXX_BATIADC_DAT1 , &raw); - val->intval =DIV_ROUND_CLOSEST (raw *745985 ,1000 ); + val->intval =DIV_ROUND_CLOSEST (raw *261095 ,350 );
DIV_ROUND_CLOSEST(raw * 149197, 200) would be marginally more accurate, but it doesn't matter in practice.
Quoted 3 lines
drivers/power/supply/ip5xxx_power.c +0
-0return 0 ;case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
Hi,
Quoted 23 lines · Samuel Holland
Quoted 7 lines · Ondrej Jirman
When current is larger than ~2A, the multiplication in
current_nowproperty overflows and the kernel reports invalid negative current value. Change the numerator and denominator while preserving their ratio to allow up to +-6A before the overflow.Fixes 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")Signed-off-by Ondrej Jirman <[email protected]>Reviewed-by Samuel Holland <[email protected]>Quoted 12 lines
--- drivers/power/supply/ip5xxx_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/ip5xxx_power.c +0
-0@@ -398,7 +398,7 @@ static int ip5xxx_battery_get_property(struct power_supply *psy, ret =ip5xxx_battery_read_adc (ip5xxx,IP5XXX_BATIADC_DAT0 ,IP5XXX_BATIADC_DAT1 , &raw);
Quoted 5 lines
drivers/power/supply/ip5xxx_power.c static int ip5xxx_battery_get_property(struct power_supply *psy, · line 401
Quoted 2 lines
drivers/power/supply/ip5xxx_power.c +1
-1- val->intval =DIV_ROUND_CLOSEST (raw *745985 ,1000 ); + val->intval =DIV_ROUND_CLOSEST (raw *261095 ,350 );
DIV_ROUND_CLOSEST(raw * 149197, 200)would be marginally more accurate, but it doesn't matter in practice.
Thanks, I queued it with that change included.
-- Sebastian
Quoted 5 lines
drivers/power/supply/ip5xxx_power.c static int ip5xxx_battery_get_property(struct power_supply *psy, · line 404
Quoted 4 lines
drivers/power/supply/ip5xxx_power.c +0
-0return 0 ;case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip