All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Tim Douglas <me@timdoug.com>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.15.y 7/7] power: supply: generic-adc-battery: fix status with no supplier
Date: Tue, 10 Nov 2026 18:10:30 -0500	[thread overview]
Message-ID: <20261110231006.55369-7-sashal@kernel.org> (raw)
In-Reply-To: <20261110231006.55369-1-sashal@kernel.org>

From: Tim Douglas <me@timdoug.com>

[ Upstream commit 8ae5a3f40045ff486826ed6b6a83e39a0f380073 ]

power_supply_am_i_supplied() returns -ENODEV when no registered power
supply supplies the battery. generic-adc-battery's gab_work() tests this
return value as a boolean, so -ENODEV takes the supplied branch and
reports CHARGING, or NOT_CHARGING if the charge-finished GPIO is asserted,
instead of DISCHARGING.

This was noticed while bringing up an out-of-tree Linux port to the
WikiReader: the driver reported CHARGING on a device powered by two AAA
batteries with no charging hardware.

Only a positive return value indicates an online supplier, so treat zero
and negative returns as discharging.

Fixes: 46cecd130d55 ("power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate")
Cc: stable@vger.kernel.org
Signed-off-by: Tim Douglas <me@timdoug.com>
Link: https://patch.msgid.link/20261013022153.6707-1-me@timdoug.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index cac0ac5caa142..e7f45ce38ce2c 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -129,7 +129,7 @@ static void gab_work(struct work_struct *work)
 	adc_bat = container_of(delayed_work, struct gab, bat_work);
 	status = adc_bat->status;
 
-	if (!power_supply_am_i_supplied(adc_bat->psy))
+	if (power_supply_am_i_supplied(adc_bat->psy) <= 0)
 		adc_bat->status =  POWER_SUPPLY_STATUS_DISCHARGING;
 	else if (gab_charge_finished(adc_bat))
 		adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
-- 
2.53.0


      parent reply	other threads:[~2026-11-10 23:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 11:08 FAILED: patch "[PATCH] power: supply: generic-adc-battery: fix status with no supplier" failed to apply to 5.15-stable tree Sasha Levin
2026-11-10 23:10 ` [PATCH 5.15.y 1/7] power: supply: generic-adc-battery: convert to managed resources Sasha Levin
2026-11-10 23:10   ` [PATCH 5.15.y 2/7] power: supply: generic-adc-battery: drop jitter delay support Sasha Levin
2026-11-10 23:10   ` [PATCH 5.15.y 3/7] power: supply: generic-adc-battery: drop charge now support Sasha Levin
2026-11-10 23:10   ` [PATCH 5.15.y 4/7] power: supply: generic-adc-battery: use simple-battery API Sasha Levin
2026-11-10 23:10   ` [PATCH 5.15.y 5/7] power: supply: generic-adc-battery: simplify read_channel logic Sasha Levin
2026-11-10 23:10   ` [PATCH 5.15.y 6/7] power: supply: generic-adc-battery: style fixes Sasha Levin
2026-11-10 23:10   ` Sasha Levin [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=20261110231006.55369-7-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=me@timdoug.com \
    --cc=sebastian.reichel@collabora.com \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.