mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Draszik" <andre.draszik@linaro.org>
To: Hans de Goede <hansg@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	 Marek Szyprowski <m.szyprowski@samsung.com>,
	 Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>,
	 Purism Kernel Team <kernel@puri.sm>,
	Sebastian Reichel <sre@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: "Peter Griffin" <peter.griffin@linaro.org>,
	"Tudor Ambarus" <tudor.ambarus@linaro.org>,
	"Juan Yescas" <jyescas@google.com>,
	"Amit Sunil Dhamne" <amitsd@google.com>,
	kernel-team@android.com, linux-pm@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"André Draszik" <andre.draszik@linaro.org>
Subject: [PATCH v2 06/11] power: supply: max17042: avoid overflow when determining health
Date: Fri, 27 Feb 2026 07:15:11 +0000	[thread overview]
Message-ID: <20260227-max77759-fg-v2-6-e50be5f191f0@linaro.org> (raw)
In-Reply-To: <20260227-max77759-fg-v2-0-e50be5f191f0@linaro.org>

If vmax has the default value of INT_MAX (e.g. because not specified in
DT), battery health is reported as over-voltage. This is because adding
any value to vmax (the vmax tolerance in this case) causes it to wrap
around, making it negative and smaller than the measured battery
voltage.

Avoid that by using size_add().

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 drivers/power/supply/max17042_battery.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index b9277f81a25d..8808c0d2ad10 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -201,7 +201,11 @@ static int max17042_get_battery_health(struct max17042_chip *chip, int *health)
 		goto out;
 	}
 
-	if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) {
+	/* avoid
+	 * /sys/class/power_supply/max170xx_battery/health:Over voltage
+	 * due to overflow
+	 */
+	if (vbatt > size_add(chip->pdata->vmax, MAX17042_VMAX_TOLERANCE)) {
 		*health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
 		goto out;
 	}

-- 
2.53.0.473.g4a7958ca14-goog


  parent reply	other threads:[~2026-02-27  7:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27  7:15 [PATCH v2 00/11] power: supply: max17042: support Maxim MAX77759 fuel gauge André Draszik
2026-02-27  7:15 ` [PATCH v2 01/11] dt-bindings: power: supply: max17042: add support for max77759 André Draszik
2026-02-27  7:15 ` [PATCH v2 02/11] dt-bindings: power: supply: max17042: support shunt-resistor-micro-ohms André Draszik
2026-02-27  7:15 ` [PATCH v2 03/11] dt-bindings: power: supply: max17042: drop formatting specifier | André Draszik
2026-02-27  7:15 ` [PATCH v2 04/11] power: supply: max17042: fix a comment typo (then -> than) André Draszik
2026-02-27  7:15 ` [PATCH v2 05/11] power: supply: max17042: use dev_err_probe() where appropriate André Draszik
2026-02-27  7:15 ` André Draszik [this message]
2026-02-27  7:15 ` [PATCH v2 07/11] power: supply: max17042: time to empty is meaningless when charging André Draszik
2026-02-27 16:47   ` Peter Griffin
2026-02-27  7:15 ` [PATCH v2 08/11] power: supply: max17042: support standard shunt-resistor-micro-ohms DT property André Draszik
2026-02-27 16:07   ` Peter Griffin
2026-02-27  7:15 ` [PATCH v2 09/11] power: supply: max17042: initial support for Maxim MAX77759 André Draszik
2026-02-27 17:00   ` Peter Griffin
2026-02-27  7:15 ` [PATCH v2 10/11] power: supply: max17042: consider task period (max77759) André Draszik
2026-02-27 17:01   ` Peter Griffin
2026-02-27  7:15 ` [PATCH v2 11/11] power: supply: max17042: report time to full (max17055 & max77759) André Draszik
2026-02-27 16:53   ` Peter Griffin

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=20260227-max77759-fg-v2-6-e50be5f191f0@linaro.org \
    --to=andre.draszik@linaro.org \
    --cc=amitsd@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hansg@kernel.org \
    --cc=jyescas@google.com \
    --cc=kernel-team@android.com \
    --cc=kernel@puri.sm \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=peter.griffin@linaro.org \
    --cc=robh@kernel.org \
    --cc=sebastian.krzyszkowiak@puri.sm \
    --cc=sre@kernel.org \
    --cc=tudor.ambarus@linaro.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

all inboxes | Powered by JetHome®