From patchwork Fri Oct 28 22:40:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 13024369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70FD2ECAAA1 for ; Fri, 28 Oct 2022 22:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiJ1WtG (ORCPT ); Fri, 28 Oct 2022 18:49:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbiJ1WsO (ORCPT ); Fri, 28 Oct 2022 18:48:14 -0400 X-Greylist: delayed 421 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 28 Oct 2022 15:48:12 PDT Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D9391E8BB9 for ; Fri, 28 Oct 2022 15:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1666996863; bh=9d6DFM/pqmRLeIc4cMgiNgVS1Vl84NV0vez6YtnLyiE=; h=From:To:Cc:Subject:Date:From; b=VTvQGgAfRWqUs+Btn43EM6g7Yo+S/b8Q0eBsjl3FEoDRNIdM2lNzPegowq/mKD7Ao vFNmfipTSDFS7ZGzsKQ4hE1Qe6nmGpiQ6d8QP2cVYn2cKNAqSTeFrlpbdgg74kcz3f XirwgNtITZGvMC9FvEx8WVwZpIUkG6l1T8jErpFc= From: Ondrej Jirman To: linux-rockchip@lists.infradead.org Cc: Ondrej Jirman , Samuel Holland , Sebastian Reichel , linux-pm@vger.kernel.org (open list:POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] power: supply: ip5xxx: Fix integer overflow in current_now calculation Date: Sat, 29 Oct 2022 00:40:52 +0200 Message-Id: <20221028224052.293693-1-megi@xff.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Reviewed-by: Samuel Holland --- 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); return 0; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: