From: hyunjungg <hj351016@gmail.com>
To: Sebastian Reichel <sre@kernel.org>, linux-pm@vger.kernel.org
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>,
Chen-Yu Tsai <wens@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Hyunjung Ko <hj351016@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect work before unregistering the supply
Date: Mon, 9 Nov 2026 13:42:11 +0900 [thread overview]
Message-ID: <20261109044212.1157357-3-hj351016@gmail.com> (raw)
In-Reply-To: <20261109044212.1157357-1-hj351016@gmail.com>
From: Hyunjung Ko <hj351016@gmail.com>
axp20x_usb_power_probe() registers the vbus_detect poll work for devm
cancellation before devm_power_supply_register(). devres unwinds in
reverse, so on unbind the power supply is freed first and the work
cancelled last. The handler calls power_supply_changed(power->supply) and
re-queues itself (and is also queued from the USB power IRQ), so an
instance running in that window dereferences the freed supply.
Register the work cancellation after the power supply, matching the
"request irqs after registering" ordering already used below.
Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index 7625366104bc..f6a7dcbd5a01 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -979,11 +979,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
- axp_data->axp20x_read_vbus);
- if (ret)
- return ret;
-
if (power->vbus_mon_bit) {
/* Enable vbus valid checking */
ret = regmap_field_write(power->vbus_mon_bit, 1);
@@ -1018,6 +1013,11 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(power->supply),
"Failed to register power supply\n");
+ ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
+ axp_data->axp20x_read_vbus);
+ if (ret)
+ return ret;
+
/* Request irqs after registering, as irqs may trigger immediately */
for (i = 0; i < axp_data->num_irq_names; i++) {
irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]);
--
2.43.0
next prev parent reply other threads:[~2026-11-09 4:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
2026-11-09 4:42 ` hyunjungg [this message]
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " hyunjungg
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=20261109044212.1157357-3-hj351016@gmail.com \
--to=hj351016@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=sebastian.reichel@collabora.com \
--cc=sre@kernel.org \
--cc=stable@vger.kernel.org \
--cc=wens@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
all inboxes | Powered by JetHome®