~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/devm-helpers.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/devm-helpers.h (Version linux-6.12-rc7) and /include/linux/devm-helpers.h (Version linux-6.1.116)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php