mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Jianing Li <m13940358460@163.com>
Cc: Iskren Chernev <me@iskren.info>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	 Marek Szyprowski <m.szyprowski@samsung.com>,
	Matheus Castello <matheus@castello.eng.br>,
	 linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] power: supply: max17040: propagate register read errors
Date: Sat, 25 Jul 2026 01:06:53 +0200	[thread overview]
Message-ID: <amPv06CIZIELsv6w@venus> (raw)
In-Reply-To: <20260724094759.3568-1-m13940358460@163.com>

[-- Attachment #1: Type: text/plain, Size: 1683 bytes --]

Hi,

On Fri, Jul 24, 2026 at 05:47:59PM +0800, Jianing Li wrote:
> max17040_get_vcell() and max17040_get_soc() ignore errors returned by
> regmap_read().  When an I2C transfer fails, the uninitialized register
> value is converted and reported to userspace as a valid voltage or state
> of charge.  The polling worker can also replace the cached state of charge
> with the bogus value and emit a spurious change event.
> 
> Propagate read errors through the power supply get_property callback and
> keep the last valid cached state of charge when polling fails.
> 
> Fixes: c6f4a42de60b ("Add MAX17040 Fuel Gauge driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jianing Li <m13940358460@163.com>
> ---
>  drivers/power/supply/max17040_battery.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
> index e94d53b36aa4..948670fb6c4a 100644
> --- a/drivers/power/supply/max17040_battery.c
> +++ b/drivers/power/supply/max17040_battery.c
> @@ -192,19 +192,21 @@ static int max17040_raw_vcell_to_uvolts(struct max17040_chip *chip, u16 vcell)
>  static int max17040_get_vcell(struct max17040_chip *chip)
>  {
>  	u32 vcell;
> +	int ret;
>  
> -	regmap_read(chip->regmap, MAX17040_VCELL, &vcell);
> +	ret = regmap_read(chip->regmap, MAX17040_VCELL, &vcell);
>  
> -	return max17040_raw_vcell_to_uvolts(chip, vcell);
> +	return ret ? ret : max17040_raw_vcell_to_uvolts(chip, vcell);

Please follow the common convention, i.e.

ret = foo();
if (ret)
    return ret;

return bar();

Greetings,

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2026-07-24 23:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  9:47 Jianing Li
2026-07-24 23:06 ` Sebastian Reichel [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=amPv06CIZIELsv6w@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=m13940358460@163.com \
    --cc=matheus@castello.eng.br \
    --cc=me@iskren.info \
    /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®