* [PATCH] power: supply: twl4030_charger: cancel workers via devm
@ 2026-07-25 7:25 Maoyi Xie
2026-07-25 16:15 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Maoyi Xie @ 2026-07-25 7:25 UTC (permalink / raw)
To: Sebastian Reichel
Cc: linux-pm, linux-kernel, stable, H . Nikolaus Schaller, Anton Vorontsov
bci is devm-allocated. Two workers (bci->work and bci->current_worker)
dereference it. twl4030_bci_remove() disables charging and masks
interrupts. It cancels neither worker. A worker pending at remove() can
run after devm frees bci.
The USB transceiver comes from devm_usb_get_phy_by_node(). devm
unregisters its notifier only after remove() returns. A cancel_work_sync()
in remove() can then race a notifier reschedule. devm_work_autocancel()
and devm_delayed_work_autocancel() avoid that. They cancel the workers
during devm release, before bci is freed.
Suggested-by: Sebastian Reichel <sre@kernel.org>
Fixes: d6ccc442b1210 ("twl4030_charger: Make the driver atomic notifier safe")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20260702172128.2001753-1-maoyixie.tju@gmail.com
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
drivers/power/supply/twl4030_charger.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 04216b2bfb6c3..d8bae2daac23d 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -14,6 +14,7 @@
#include <linux/err.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/devm-helpers.h>
#include <linux/interrupt.h>
#include <linux/mfd/twl.h>
#include <linux/power_supply.h>
@@ -1002,8 +1003,18 @@ static int twl4030_bci_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, bci);
- INIT_WORK(&bci->work, twl4030_bci_usb_work);
- INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker);
+ /* Register current_worker first: devm cancels in reverse order, and
+ * bci->work can reschedule current_worker.
+ */
+ ret = devm_delayed_work_autocancel(&pdev->dev, &bci->current_worker,
+ twl4030_current_worker);
+ if (ret)
+ return ret;
+
+ ret = devm_work_autocancel(&pdev->dev, &bci->work,
+ twl4030_bci_usb_work);
+ if (ret)
+ return ret;
bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac");
if (IS_ERR(bci->channel_vac)) {
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: twl4030_charger: cancel workers via devm
2026-07-25 7:25 [PATCH] power: supply: twl4030_charger: cancel workers via devm Maoyi Xie
@ 2026-07-25 16:15 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2026-07-25 16:15 UTC (permalink / raw)
To: Sebastian Reichel, Maoyi Xie
Cc: linux-pm, linux-kernel, stable, H . Nikolaus Schaller, Anton Vorontsov
On Sat, 25 Jul 2026 15:25:40 +0800, Maoyi Xie wrote:
> bci is devm-allocated. Two workers (bci->work and bci->current_worker)
> dereference it. twl4030_bci_remove() disables charging and masks
> interrupts. It cancels neither worker. A worker pending at remove() can
> run after devm frees bci.
>
> The USB transceiver comes from devm_usb_get_phy_by_node(). devm
> unregisters its notifier only after remove() returns. A cancel_work_sync()
> in remove() can then race a notifier reschedule. devm_work_autocancel()
> and devm_delayed_work_autocancel() avoid that. They cancel the workers
> during devm release, before bci is freed.
>
> [...]
Applied, thanks!
[1/1] power: supply: twl4030_charger: cancel workers via devm
commit: 6eba34732524067da2aad5ddfdfbc641ded10e9e
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-25 16:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-25 7:25 [PATCH] power: supply: twl4030_charger: cancel workers via devm Maoyi Xie
2026-07-25 16:15 ` Sebastian Reichel
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®