Linux Power Management development
 help / color / mirror / Atom feed
From: Jerry Lv <Jerry.Lv@axis.com>
To: "Pali Rohár" <pali@kernel.org>, "Sebastian Reichel" <sre@kernel.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<kernel@axis.com>, Jerry Lv <Jerry.Lv@axis.com>
Subject: [PATCH] power: supply: bq27xxx_battery: Do not return ENODEV when busy
Date: Fri, 13 Sep 2024 16:45:37 +0800	[thread overview]
Message-ID: <20240913-foo-fix2-v1-1-a0f499404f3a@axis.com> (raw)

Multiple applications may access the device gauge at the same time, so the
gauge may be busy and EBUSY will be returned. The driver will set a flag to
record the EBUSY state, and this flag will be kept until the next periodic
update. When this flag is set, bq27xxx_battery_get_property() will just
return ENODEV until the flag is updated.

Even if the gauge was busy during the last accessing attempt, returning
ENODEV is not ideal, and can cause confusion in the applications layer.

Instead, retry accessing the gauge to update the properties is as expected.
The gauge typically recovers from busy state within a few milliseconds, and
the cached flag will not cause issues while updating the properties.

Signed-off-by: Jerry Lv <Jerry.Lv@axis.com>
---
 drivers/power/supply/bq27xxx_battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 750fda543308..eefbb5029a3b 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -2029,7 +2029,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
 		bq27xxx_battery_update_unlocked(di);
 	mutex_unlock(&di->lock);
 
-	if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
+	if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0 && di->cache.flags != -EBUSY)
 		return -ENODEV;
 
 	switch (psp) {

---
base-commit: da3ea35007d0af457a0afc87e84fddaebc4e0b63
change-id: 20240913-foo-fix2-a0d79db86a0b

Best regards,
-- 
Jerry Lv <Jerry.Lv@axis.com>


             reply	other threads:[~2024-09-13  8:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13  8:45 Jerry Lv [this message]
2024-09-13 21:27 ` [PATCH] power: supply: bq27xxx_battery: Do not return ENODEV when busy Pali Rohár
     [not found]   ` <VI1PR02MB1007663D83495B0594DE794C7F4662@VI1PR02MB10076.eurprd02.prod.outlook.com>
2024-09-14  8:24     ` Pali Rohár
2024-09-23  8:14       ` Jerry Lv
2024-09-23 18:16         ` Pali Rohár
2024-09-24  3:34           ` Jerry Lv
2024-09-24 19:02             ` Pali Rohár

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=20240913-foo-fix2-v1-1-a0f499404f3a@axis.com \
    --to=jerry.lv@axis.com \
    --cc=kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=sre@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox