From: sashiko-bot@kernel.org
To: "Vincent Cloutier" <vincent.cloutier@icloud.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 01/11] power: supply: Add registration init callback
Date: Mon, 27 Jul 2026 01:28:53 +0000 [thread overview]
Message-ID: <20260727012853.8764C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260727011319.621794-2-vincent.cloutier@icloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free of `psy->changed_work` in `__power_supply_register()` error path.
--
--- Patch [1]: [PATCH v4 01/11] power: supply: Add registration init callback ---
commit 91f996f8711a8d5770312f212add1d5d3cecfc83
Author: Vincent Cloutier <vincent@cloutier.co>
power: supply: Add registration init callback
This commit adds an optional registration init callback for battery drivers
to consume monitored-battery data before their power_supply is visible.
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 2532e221b2e19..3ed4c253706f3 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1624,6 +1624,14 @@ __power_supply_register(struct device *parent,
> init_rwsem(&psy->extensions_sem);
> INIT_LIST_HEAD(&psy->extensions);
>
> + if (desc->init) {
> + rc = desc->init(psy);
> + if (WARN_ON_ONCE(rc > 0))
> + rc = -EINVAL;
> + if (rc)
> + goto check_supplies_failed;
> + }
> +
> rc = device_add(dev);
[Severity: High]
This is a pre-existing issue, but does the error path handling after this
device_add() call lead to a use-after-free of psy->changed_work?
If device_add() succeeds, the device is published to the power_supply class.
Another thread can then find the published device via
power_supply_get_by_name(), take a reference, and call power_supply_changed(),
which queues psy->changed_work on the system workqueue.
If a subsequent initialization step in __power_supply_register() fails
(such as psy_register_thermal), the code jumps to the error path:
register_thermal_failed:
wakeup_init_failed:
device_del(dev);
device_add_failed:
check_supplies_failed:
dev_set_name_failed:
put_device(dev);
return ERR_PTR(rc);
This drops the local reference to the power supply structure via put_device()
but omits canceling any potentially queued work with
cancel_work_sync(&psy->changed_work).
Once the other thread drops its reference, psy is freed by
power_supply_dev_release(). The system workqueue will then dereference the
freed memory when it executes power_supply_changed_work().
> if (rc)
> goto device_add_failed;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727011319.621794-1-vincent.cloutier@icloud.com?part=1
next prev parent reply other threads:[~2026-07-27 1:28 UTC|newest]
Thread overview: 16+ 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 [this message]
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
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
2026-07-27 9:08 ` Krzysztof Kozlowski
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=20260727012853.8764C1F00A3A@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 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.