]> Git Repo - J-linux.git/blobdiff - include/linux/devm-helpers.h
Merge branch 'fixes-v5.14' into fixes
[J-linux.git] / include / linux / devm-helpers.h
index f40f77717a245881d54bcff12082b147e03934d5..74891802200d6257add43f932e8b955af2b7738a 100644 (file)
@@ -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
This page took 0.028543 seconds and 4 git commands to generate.