Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vincent Cloutier" <vincent.cloutier@icloud.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 05/11] power: supply: max17042_battery: Propagate status register errors
Date: Mon, 27 Jul 2026 01:31:04 +0000	[thread overview]
Message-ID: <20260727013104.863351F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260727011319.621794-6-vincent.cloutier@icloud.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Probe failure leaves device interrupts actively enabled on the hardware, potentially causing an interrupt storm.
- [High] Multiple hardware configuration functions ignore the return value of regmap_read, using uninitialized stack variables to write arbitrary values to hardware registers.
- [High] The threaded IRQ handler returns IRQ_HANDLED upon failing to read the device status, defeating the kernel's spurious interrupt detector and risking a hard interrupt storm.
--

--- Patch [5]: [PATCH v4 05/11] power: supply: max17042_battery: Propagate status register errors ---
commit bced78410601fcdc0467a660acdbfd2bb2e4527e
Author: Vincent Cloutier <vincent@cloutier.co>

power: supply: max17042_battery: Propagate status register errors

The driver adds error checking for the initial STATUS read and final POR
clear during initialization. A failed read will now propagate the error
instead of ignoring it, and the POR-clear result is returned directly.

> diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
> index 38abd3604643b..9210bdb4d67eb 100644
> --- a/drivers/power/supply/max17042_battery.c
> +++ b/drivers/power/supply/max17042_battery.c
> @@ -908,8 +908,7 @@ static int max17042_init_chip(struct max17042_chip *chip)
>  	}
>  
>  	/* Init complete, Clear the POR bit */
> -	regmap_update_bits(map, MAX17042_STATUS, STATUS_POR_BIT, 0x0);
> -	return 0;
> +	return regmap_clear_bits(map, MAX17042_STATUS, STATUS_POR_BIT);
>  }
>  
>  static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)

[Severity: High]
This is a pre-existing issue, but functions like max17042_set_soc_threshold
and max17042_load_new_capacity_params ignore the return value of regmap_read.

If the I2C read fails, can this lead to uninitialized stack variables
(soc, vfSoc, full_cap0) being bit-shifted and written directly back
to critical hardware registers?

For example:
drivers/power/supply/max17042_battery.c:max17042_set_soc_threshold() {
    ...
    regmap_read(map, MAX17042_RepSOC, &soc);
    soc_tr = (soc + off) << 8;
    ...
}

[ ... ]

> @@ -1248,7 +1247,10 @@ static int max17042_probe(struct i2c_client *client, struct device *dev, int irq
>  
>  	chip->irq = irq;
>  
> -	regmap_read(chip->regmap, MAX17042_STATUS, &val);
> +	ret = regmap_read(chip->regmap, MAX17042_STATUS, &val);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to read status\n");
> +

[Severity: High]
This isn't a bug introduced by this patch, but returning here exposes a missing
cleanup step.

If this new read fails, we return an error and the devm framework frees
the IRQ handler. However, earlier in max17042_probe, we enable hardware alerts
with regmap_update_bits(chip->regmap, MAX17042_CONFIG, CFG_ALRT_BIT_ENBL, ...).

Since there is no devm-managed cleanup or manual unwind for this alert
enablement, and the IRQ is requested with IRQF_SHARED, could this leave the
device actively asserting the interrupt line without a registered handler,
resulting in an interrupt storm?

>  	if (val & STATUS_POR_BIT) {
>  		ret = devm_delayed_work_autocancel(dev, &chip->work,
>  						   max17042_init_worker);

[Severity: High]
This is a pre-existing issue, but I noticed a potential problem in
max17042_thread_handler():

drivers/power/supply/max17042_battery.c:max17042_thread_handler() {
    ...
    ret = regmap_read(chip->regmap, MAX17042_STATUS, &val);
    if (ret)
        return IRQ_HANDLED;
    ...
}

If regmap_read fails (e.g., due to a transient I2C bus error), the handler
returns IRQ_HANDLED without clearing the interrupt bits on the device.

Since the handler reports success (IRQ_HANDLED) while the physical device
is still asserting the shared interrupt line, does this bypass the kernel's
spurious interrupt detector and risk a hard interrupt storm?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727011319.621794-1-vincent.cloutier@icloud.com?part=5

  reply	other threads:[~2026-07-27  1:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27  1:12 [PATCH v4 00/11] power: supply: initialize MAX17055 from battery info Vincent Cloutier
2026-07-27  1:12 ` [PATCH v4 01/11] power: supply: Add registration init callback Vincent Cloutier
2026-07-27  1:28   ` sashiko-bot
2026-07-27  1:13 ` [PATCH v4 02/11] power: supply: max17042_battery: Separate MAX17055 initialization Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 03/11] power: supply: max17042_battery: Use bool for init_complete Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 04/11] power: supply: max17042_battery: Convert initialization to delayed work Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 05/11] power: supply: max17042_battery: Propagate status register errors Vincent Cloutier
2026-07-27  1:31   ` sashiko-bot [this message]
2026-07-27  1:13 ` [PATCH v4 06/11] power: supply: max17042_battery: Retry failed MAX17055 initialization Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 07/11] power: supply: max17042_battery: Program MAX17055 EZ Config values Vincent Cloutier
2026-07-27  1:28   ` sashiko-bot
2026-07-27  1:13 ` [PATCH v4 08/11] power: supply: max17042_battery: Follow MAX17055 POR sequence Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 09/11] power: supply: max17042_battery: Initialize MAX17055 from battery info Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 10/11] power: supply: max17042_battery: Honor MAX17055 charge voltage Vincent Cloutier
2026-07-27  1:13 ` [PATCH v4 11/11] dt-bindings: power: supply: max17042: Allow generic power-supply properties Vincent Cloutier

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=20260727013104.863351F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vincent.cloutier@icloud.com \
    /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