summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2021-06-18 15:30:32 +0200
committerHans de Goede <hdegoede@redhat.com>2021-06-18 15:30:32 +0200
commit94f31542f176d4218dfca92a7d9f96ebb0a3ea31 (patch)
tree45c3e3fbdd90348bea899e1ab91da4a296df1414 /include/linux
parentaa2ddd24257213bdfd2f65058531810ac57455dc (diff)
parent87ee8de23c9df3a368504f34cf3d7f9be9207717 (diff)
Merge tag 'devm-helpers-v5.14-1' into review-hans
Signed tag for the immutable devm-helpers branch for merging into the extcon and pdx86 trees.
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/devm-helpers.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h
index f40f77717a24..74891802200d 100644
--- a/include/linux/devm-helpers.h
+++ b/include/linux/devm-helpers.h
@@ -51,4 +51,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