1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 #ifndef __LINUX_DEVM_HELPERS_H 3 #define __LINUX_DEVM_HELPERS_H 4 5 /* 6 * Functions which do automatically cancel ope 7 * driver detach. 8 * 9 * These should be helpful to avoid mixing the 10 * management which can be source of annoying, 11 * hard-to-reproduce bugs. 12 * 13 * Please take into account that devm based ca 14 * time after the remove() is ran. 15 * 16 * Thus mixing devm and manual resource manage 17 * when unwinding operations with dependencies 18 * is typical example where IRQs are often dev 19 * cleaned at remove(). If IRQs are not manual 20 * often the case when we use devm for IRQs) w 21 * remove() - and before devm managed IRQs are 22 * and schedule a work item which won't be can 23 * already ran. 24 */ 25 26 #include <linux/device.h> 27 #include <linux/workqueue.h> 28 29 static inline void devm_delayed_work_drop(void 30 { 31 cancel_delayed_work_sync(res); 32 } 33 34 /** 35 * devm_delayed_work_autocancel - Resource-man 36 * @dev: Device which lifetime work is 37 * @w: Work item to be queued 38 * @worker: Worker function 39 * 40 * Initialize delayed work which is automatica 41 * detached. A few drivers need delayed work w 42 * driver is detached to avoid accessing remov 43 * devm_delayed_work_autocancel() can be used 44 * cancellation when driver is detached. 45 */ 46 static inline int devm_delayed_work_autocancel 47 48 49 { 50 INIT_DELAYED_WORK(w, worker); 51 return devm_add_action(dev, devm_delay 52 } 53 54 static inline void devm_work_drop(void *res) 55 { 56 cancel_work_sync(res); 57 } 58 59 /** 60 * devm_work_autocancel - Resource-managed wor 61 * @dev: Device which lifetime work is 62 * @w: Work to be added (and automati 63 * @worker: Worker function 64 * 65 * Initialize work which is automatically canc 66 * A few drivers need to queue work which must 67 * is detached to avoid accessing removed reso 68 * devm_work_autocancel() can be used to omit 69 * cancellation when driver is detached. 70 */ 71 static inline int devm_work_autocancel(struct 72 struct 73 work_fu 74 { 75 INIT_WORK(w, worker); 76 return devm_add_action(dev, devm_work_ 77 } 78 79 #endif 80
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.