Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3084876rwi; Fri, 28 Oct 2022 15:46:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fIGFT1SUJtyTzpRJLPbDBLRtH+6AMe8P6QDn03mCMZau+Vpl5sjEE4DCQspADzkiLUlFu X-Received: by 2002:a17:907:75d4:b0:78d:efa7:f78c with SMTP id jl20-20020a17090775d400b0078defa7f78cmr1416333ejc.454.1666997196308; Fri, 28 Oct 2022 15:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666997196; cv=none; d=google.com; s=arc-20160816; b=vXI0NrHTZHOBdHbXEOFR05P5cFv3jagvW19LuRbL4TCH82RUsTYtIVRLYiWxpetxHX JmGkEhTzvrmqidIwyCpuWauvHCiYqa1mjV6mTSdIcpU3XR+qxRrraKYN2VMlW+xC2U7/ Jy4vHQWfWCSPg+/tObU4NjjCo6xqpLU9nlyzc8am1U1G0VNog68aVybsAXrAQDKUKaod tADiKWywW9EWeLk0LakSrwR/ZrQ6JmHyzu205f1Ny0F2zjAvWVU6hu58MARs4t4+U8pM FBdabrHSA3BBtGRzy/uLP/KvbXmw25KCOABkA7VEOQDbIRHwH+9oZGLdBV43NvcdBFI/ SwhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sijITe/ZpsFfdWris7uNJS58AyGje2V80AYUTpGPGE8=; b=u8k+2r0NBUG0zqHW6+XJyMlTqRfQAP/Y45fIvTkRdHNB+jAZUWryvZ4d/JThxPbxbE /TeaBBjGpGRD6MyjnMudju3brrubL5rSIPp034hJuziSEJ1HgOzx/EU9NvntEV7gDuFv Jm+71+ZWEQdXoCRzll9WkiMjAd6wZK72A+rHLhPRG0+CYU9hVliTGOqiuDICdLqP8y9a xWVl5Tl6fcBPYSFRKbg13ss9sJ1blKl7XSbxSlnpTSaTeZRmgCIyX4TuRDG7SUVCScpP VjzBxF/brCJ1iSiBiuRgAUgFAqu73CDo9dLzgdHg44NiFRK1Nuv/TgRTXIghQ/bPdzar VaCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=VTvQGgAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a50cd02000000b0045c93142111si3687646edi.70.2022.10.28.15.46.11; Fri, 28 Oct 2022 15:46:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=VTvQGgAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJ1WlU (ORCPT + 99 others); Fri, 28 Oct 2022 18:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbiJ1WlQ (ORCPT ); Fri, 28 Oct 2022 18:41:16 -0400 Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52C11DBBD2 for ; Fri, 28 Oct 2022 15:41:11 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_PASS,T_SPF_HELO_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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: -- 2.38.1