From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Samuel Holland <samuel@sholland.org>
Cc: Ondrej Jirman <megi@xff.cz>,
"open list:POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS"
<linux-pm@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
linux-rockchip@lists.infradead.org
Subject: Re: [PATCH] power: supply: ip5xxx: Fix integer overflow in current_now calculation
Date: Tue, 1 Nov 2022 01:08:33 +0100 [thread overview]
Message-ID: <20221101000833.hwuhc7ki6b33fnhf@mercury.elektranox.org> (raw)
In-Reply-To: <6b23af14-340d-b7b5-7d20-14fae03f724c@sholland.org>
[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]
Hi,
On Fri, Oct 28, 2022 at 06:06:07PM -0500, Samuel Holland wrote:
> 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@xff.cz>
>
> Reviewed-by: Samuel Holland <samuel@sholland.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.
Thanks, I queued it with that change included.
-- Sebastian
>
> > return 0;
> >
> > case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2022-11-01 0:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 22:40 [PATCH] power: supply: ip5xxx: Fix integer overflow in current_now calculation Ondrej Jirman
2022-10-28 23:06 ` Samuel Holland
2022-11-01 0:08 ` Sebastian Reichel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221101000833.hwuhc7ki6b33fnhf@mercury.elektranox.org \
--to=sebastian.reichel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=megi@xff.cz \
--cc=samuel@sholland.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).