From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>,
Hans de Goede <hdegoede@redhat.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10.y 2/3] devm-helpers: Add resource managed version of work init
Date: Wed, 9 Sep 2026 13:00:00 -0400 [thread overview]
Message-ID: <20260909170001.3156731-2-sashal@kernel.org> (raw)
In-Reply-To: <20260909170001.3156731-1-sashal@kernel.org>
From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
[ Upstream commit 7a2c4cc537fa9f05fe90812e7d789b9faf7eb869 ]
A few drivers which need a work-queue must cancel work at driver detach.
Some of those implement remove() solely for this purpose. Help drivers to
avoid unnecessary remove and error-branch implementation by adding managed
verision of work initialization. This will also help drivers to avoid
mixing manual and devm based unwinding when other resources are handled by
devm.
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/94ff4175e7f2ff134ed2fa7d6e7641005cc9784b.1623146580.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Stable-dep-of: 6eba34732524 ("power: supply: twl4030_charger: cancel workers via devm")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/devm-helpers.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h
index f64e0c9f3763c..50557f04ce802 100644
--- a/include/linux/devm-helpers.h
+++ b/include/linux/devm-helpers.h
@@ -50,4 +50,29 @@ static inline int devm_delayed_work_autocancel(struct device *dev,
return devm_add_action(dev, devm_delayed_work_drop, w);
}
+static inline void devm_work_drop(void *res)
+{
+ cancel_work_sync(res);
+}
+
+/**
+ * devm_work_autocancel - Resource-managed work allocation
+ * @dev: Device which lifetime work is bound to
+ * @w: Work to be added (and automatically cancelled)
+ * @worker: Worker function
+ *
+ * Initialize work which is automatically cancelled when driver is detached.
+ * A few drivers need to queue work which must be cancelled before driver
+ * is detached to avoid accessing removed resources.
+ * devm_work_autocancel() can be used to omit the explicit
+ * cancelleation when driver is detached.
+ */
+static inline int devm_work_autocancel(struct device *dev,
+ struct work_struct *w,
+ work_func_t worker)
+{
+ INIT_WORK(w, worker);
+ return devm_add_action(dev, devm_work_drop, w);
+}
+
#endif
--
2.53.0
next prev parent reply other threads:[~2026-09-09 17:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 15:04 FAILED: patch "[PATCH] power: supply: twl4030_charger: cancel workers via devm" failed to apply to 5.10-stable tree gregkh
2026-09-09 16:59 ` [PATCH 5.10.y 1/3] workqueue: Add resource managed version of delayed work init Sasha Levin
2026-09-09 17:00 ` Sasha Levin [this message]
2026-09-09 17:00 ` [PATCH 5.10.y 3/3] power: supply: twl4030_charger: cancel workers via devm Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2026-09-16 16:01 FAILED: patch "[PATCH] hwmon: (gpio-fan) Fix use-after-free in alarm work" failed to apply to 5.10-stable tree gregkh
2026-09-17 2:18 ` [PATCH 5.10.y 1/3] workqueue: Add resource managed version of delayed work init Sasha Levin
2026-09-17 2:18 ` [PATCH 5.10.y 2/3] devm-helpers: Add resource managed version of " Sasha Levin
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=20260909170001.3156731-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hdegoede@redhat.com \
--cc=krzysztof.kozlowski@canonical.com \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=stable@vger.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