lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 28 Oct 2022 18:06:07 -0500
From:   Samuel Holland <samuel@...lland.org>
To:     Ondrej Jirman <megi@....cz>, Sebastian Reichel <sre@...nel.org>
Cc:     "open list:POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS" 
        <linux-pm@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>,
        linux-rockchip@...ts.infradead.org
Subject: Re: [PATCH] power: supply: ip5xxx: Fix integer overflow in
 current_now calculation

On 10/28/22 17:40, Ondrej Jirman wrote:
> 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.
> 
> Fixes: 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")
> Signed-off-by: Ondrej Jirman <megi@....cz>

Reviewed-by: Samuel Holland <samuel@...lland.org>

> ---
>  drivers/power/supply/ip5xxx_power.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
> index 02ee4d252a3e..f39cb2f7aa11 100644
> --- a/drivers/power/supply/ip5xxx_power.c
> +++ b/drivers/power/supply/ip5xxx_power.c
> @@ -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.

>  		return 0;
>  
>  	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ