Message ID | 20230214132052.1556699-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2969198wrn; Tue, 14 Feb 2023 05:24:19 -0800 (PST) X-Google-Smtp-Source: AK7set94yGqhzZzp46dinhPfu8tjEWxIC21PQOgSrROrpwH1ZozgkIHMek7vkXuf3cXvYv/iXnVa X-Received: by 2002:a17:906:8396:b0:8b1:3002:bd6d with SMTP id p22-20020a170906839600b008b13002bd6dmr1856987ejx.31.1676381059184; Tue, 14 Feb 2023 05:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676381059; cv=none; d=google.com; s=arc-20160816; b=cBRL9ZivoF9x/SXrNxAHwqSUwJ7jidU8GLi4rgkZmDn570CyNF7Vf+FLDZxq2QPxj6 C+/SiRKm2QUOR++EdysmzQlS8zr6fR5h9aoAdglkz8WLcO6iAIp6zpeZ2CGinTF+g2Cm fK36TfP9xRfWM0PLhpAGbfZkDB4JJ733fXh4hRlr7om6jDlvUzpBuvvnNdU4KcuRSIN4 nl8DA6vvJEVPxBqjl7GS5CE8qJ4Yy3bpo3647W8z+3iZEML3cld5jI+Vk/JZpPNunBrY yE0abfnAKS88nHXPnOPxV7K1er6HMV/daTjvvX8Xdq5Ah6CbPdXP93p4ZJAAbtLsdUoB O4Uw== 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=+NkeJTZ9jRxZwyeHxc8Q5BjGr/qG9SWWeArC9by5vLY=; b=i6PhF6CHwhd64tBi93r5C1gZAjpIvuJKpxH9VUkuQHNDjFSi7CBnGIjb/K6emaU4DG vHaU6nRrGlSVZ36QMpQdoqPSgAXu5reOMDLfO8xT4UCjA6PY1j+JBFt+Q+C0oLMJEQIj zHRIJe4nbWBshMIADVSgyzdPtxMeohdGJhI1igpx7r9cLsfV0e6dd2xGYqGZbJn8fyxi cbV1Zn/EMBtT49ruiegU5nMceFPmdYKpab4QUBjLxYUp5OlSwC0/T4lqRxlSPNHQQEN8 xpfXxKxNh0JuTeNlICFaGQ9l3Ia8O0w5U8GsiZn+WR0KckaTAcOAqP/JNF5Z4hrZh++y iIVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BM5Iz0iw; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25-20020a170906209900b008b1348199d7si1113784ejq.785.2023.02.14.05.23.55; Tue, 14 Feb 2023 05:24:19 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=BM5Iz0iw; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbjBNNVR (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Tue, 14 Feb 2023 08:21:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbjBNNVP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Feb 2023 08:21:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F5EF279B7; Tue, 14 Feb 2023 05:20:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AFE1B61637; Tue, 14 Feb 2023 13:20:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1588DC433D2; Tue, 14 Feb 2023 13:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676380856; bh=9m8ZbKJsD+az2elSMPiB/zCuKKeWwdmecOz4rRFlokw=; h=From:To:Cc:Subject:Date:From; b=BM5Iz0iwcVDt6wMsJwSQqIgE769d6X+hnI4PuaEX4j/mDAXprrZJCBYjc49bgctp2 5AgbRg2mNfecieyWcPOz7FfuAEJ6jKznh9yFsaCG8fQC7uaGLhh25LTSOEVcu4bnNr Dwo588zvSBn/mojAkTU9P6Vc4OlzY4CSEVQyF4r/Fj3y7Aes9IJa+okDwm0fuCOaeH Eez00iOt94mjXZTDhGcC1QvpSXE+GvU811v+G+B5P2+j/rpt8Tt1Cm9+h8WJ2GXarK hszGdJV/dWlMpc94Au/83/mGc3pX7mAm07FIg6/MJOwQk58h3dH5G13qp+i319IcOi 1XHGvdaNI3+8w== From: Arnd Bergmann <arnd@kernel.org> To: Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Sebastian Reichel <sre@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de>, Konrad Dybcio <konrad.dybcio@linaro.org>, Neil Armstrong <neil.armstrong@linaro.org>, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] power: supply: qcom_battmgr: remove bogus do_div() Date: Tue, 14 Feb 2023 14:20:42 +0100 Message-Id: <20230214132052.1556699-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757812945855899791?= X-GMAIL-MSGID: =?utf-8?q?1757812945855899791?= |
Series |
power: supply: qcom_battmgr: remove bogus do_div()
|
|
Commit Message
Arnd Bergmann
Feb. 14, 2023, 1:20 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The argument to do_div() is a 32-bit integer, and it was read from a 32-bit register so there is no point in doing a 64-bit division on it. On 32-bit arm, do_div() causes a compile-time warning here: include/asm-generic/div64.h:238:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] 238 | __rem = __div64_32(&(n), __base); \ | ^~~~ | | | unsigned int * drivers/power/supply/qcom_battmgr.c:1130:4: note: in expansion of macro 'do_div' 1130 | do_div(battmgr->status.percent, 100); Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- drivers/power/supply/qcom_battmgr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On 14.02.2023 14:20, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The argument to do_div() is a 32-bit integer, and it was read from a > 32-bit register so there is no point in doing a 64-bit division on it. > > On 32-bit arm, do_div() causes a compile-time warning here: > > include/asm-generic/div64.h:238:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] > 238 | __rem = __div64_32(&(n), __base); \ > | ^~~~ > | | > | unsigned int * > drivers/power/supply/qcom_battmgr.c:1130:4: note: in expansion of macro 'do_div' > 1130 | do_div(battmgr->status.percent, 100); > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Konrad > drivers/power/supply/qcom_battmgr.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c > index ec31f887184f..de77df97b3a4 100644 > --- a/drivers/power/supply/qcom_battmgr.c > +++ b/drivers/power/supply/qcom_battmgr.c > @@ -1126,8 +1126,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, > battmgr->info.charge_type = le32_to_cpu(resp->intval.value); > break; > case BATT_CAPACITY: > - battmgr->status.percent = le32_to_cpu(resp->intval.value); > - do_div(battmgr->status.percent, 100); > + battmgr->status.percent = le32_to_cpu(resp->intval.value) / 100; > break; > case BATT_VOLT_OCV: > battmgr->status.voltage_ocv = le32_to_cpu(resp->intval.value);
Hi, On Tue, Feb 14, 2023 at 02:36:03PM +0100, Konrad Dybcio wrote: > On 14.02.2023 14:20, Arnd Bergmann wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > The argument to do_div() is a 32-bit integer, and it was read from a > > 32-bit register so there is no point in doing a 64-bit division on it. > > > > On 32-bit arm, do_div() causes a compile-time warning here: > > > > include/asm-generic/div64.h:238:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] > > 238 | __rem = __div64_32(&(n), __base); \ > > | ^~~~ > > | | > > | unsigned int * > > drivers/power/supply/qcom_battmgr.c:1130:4: note: in expansion of macro 'do_div' > > 1130 | do_div(battmgr->status.percent, 100); > > > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > > --- > Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Needs to go through the Qualcomm tree: Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> -- Sebastian > > drivers/power/supply/qcom_battmgr.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c > > index ec31f887184f..de77df97b3a4 100644 > > --- a/drivers/power/supply/qcom_battmgr.c > > +++ b/drivers/power/supply/qcom_battmgr.c > > @@ -1126,8 +1126,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, > > battmgr->info.charge_type = le32_to_cpu(resp->intval.value); > > break; > > case BATT_CAPACITY: > > - battmgr->status.percent = le32_to_cpu(resp->intval.value); > > - do_div(battmgr->status.percent, 100); > > + battmgr->status.percent = le32_to_cpu(resp->intval.value) / 100; > > break; > > case BATT_VOLT_OCV: > > battmgr->status.voltage_ocv = le32_to_cpu(resp->intval.value);
On Tue, Feb 14, 2023 at 2:23 PM Arnd Bergmann <arnd@kernel.org> wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The argument to do_div() is a 32-bit integer, and it was read from a > 32-bit register so there is no point in doing a 64-bit division on it. > > On 32-bit arm, do_div() causes a compile-time warning here: > > include/asm-generic/div64.h:238:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] > 238 | __rem = __div64_32(&(n), __base); \ > | ^~~~ > | | > | unsigned int * > drivers/power/supply/qcom_battmgr.c:1130:4: note: in expansion of macro 'do_div' > 1130 | do_div(battmgr->status.percent, 100); > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Gr{oetje,eeting}s, Geert
Hi Linus, On Tue, Feb 14, 2023 at 02:20:42PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The argument to do_div() is a 32-bit integer, and it was read from a > 32-bit register so there is no point in doing a 64-bit division on it. > > On 32-bit arm, do_div() causes a compile-time warning here: > > include/asm-generic/div64.h:238:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] > 238 | __rem = __div64_32(&(n), __base); \ > | ^~~~ > | | > | unsigned int * > drivers/power/supply/qcom_battmgr.c:1130:4: note: in expansion of macro 'do_div' > 1130 | do_div(battmgr->status.percent, 100); > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > drivers/power/supply/qcom_battmgr.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c > index ec31f887184f..de77df97b3a4 100644 > --- a/drivers/power/supply/qcom_battmgr.c > +++ b/drivers/power/supply/qcom_battmgr.c > @@ -1126,8 +1126,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, > battmgr->info.charge_type = le32_to_cpu(resp->intval.value); > break; > case BATT_CAPACITY: > - battmgr->status.percent = le32_to_cpu(resp->intval.value); > - do_div(battmgr->status.percent, 100); > + battmgr->status.percent = le32_to_cpu(resp->intval.value) / 100; > break; > case BATT_VOLT_OCV: > battmgr->status.voltage_ocv = le32_to_cpu(resp->intval.value); > -- > 2.39.1 > Would you be able to take this patch directly? It seems obviously correctTM, has an ack from Sebastian [1], and without it, 32-bit allmodconfig builds are broken [2] (the other warning in that log has a fix on the way to you soon). [1]: https://lore.kernel.org/20230214220210.cpviycsmcppylkgj@mercury.elektranox.org/ [2]: https://storage.tuxsuite.com/public/clangbuiltlinux/continuous-integration2/builds/2MPmxwvmQ7FdpiMhdQN2ZJhcoUP/build.log Cheers, Nathan
On Wed, Mar 1, 2023 at 10:16 AM Nathan Chancellor <nathan@kernel.org> wrote: > > Would you be able to take this patch directly? It seems obviously > correctTM, has an ack from Sebastian [1], and without it, 32-bit > allmodconfig builds are broken [2] (the other warning in that log has a > fix on the way to you soon). Ok, I've taken it directly. However, the whole "seems obviously correct" is true in the sense that it now doesn't complain (and doesn't overwrite an "int" with a 64-bit value. The actual code still looks odd. Is that return value for BATT_CAPACITY truly in that odd "hundredths of percent" format, where dividing it by 100 gives you whole percent? Because "hundredths of percent" strikes me as a very odd interface. Even for some firmware interface. I realize that anything is possible with strange firmware, but still... Linus
Hi, On Wed, Mar 01, 2023 at 10:50:33AM -0800, Linus Torvalds wrote: > On Wed, Mar 1, 2023 at 10:16 AM Nathan Chancellor <nathan@kernel.org> wrote: > > Would you be able to take this patch directly? It seems obviously > > correctTM, has an ack from Sebastian [1], and without it, 32-bit > > allmodconfig builds are broken [2] (the other warning in that log has a > > fix on the way to you soon). > > Ok, I've taken it directly. > > However, the whole "seems obviously correct" is true in the sense that > it now doesn't complain (and doesn't overwrite an "int" with a 64-bit > value. > > The actual code still looks odd. Is that return value for > BATT_CAPACITY truly in that odd "hundredths of percent" format, > where dividing it by 100 gives you whole percent? > > Because "hundredths of percent" strikes me as a very odd interface. > Even for some firmware interface. I realize that anything is possible > with strange firmware, but still... I don't have the documentation for this Qualcomm interface, but I remember somebody from Qualcomm asking for a power-supply property exposing "hundredths of percent" to userspace some years ago (with the rationale, that percent was not precise enough). For reference: The upstream solution for that is exposing ENERGY_NOW and ENERGY_FULL in µWh (or CHARGE_NOW + CHARGE_FULL in µAh depending on the fuel-gauge's capabilities), which is even more precise. -- Sebastian
diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c index ec31f887184f..de77df97b3a4 100644 --- a/drivers/power/supply/qcom_battmgr.c +++ b/drivers/power/supply/qcom_battmgr.c @@ -1126,8 +1126,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, battmgr->info.charge_type = le32_to_cpu(resp->intval.value); break; case BATT_CAPACITY: - battmgr->status.percent = le32_to_cpu(resp->intval.value); - do_div(battmgr->status.percent, 100); + battmgr->status.percent = le32_to_cpu(resp->intval.value) / 100; break; case BATT_VOLT_OCV: battmgr->status.voltage_ocv = le32_to_cpu(resp->intval.value);