It seems that lots of Linux Kernel components provide macros to help the programmer easily declare a variable statically at runtime, which is allocated on the stack (doesn't mean a static keyword); for example, DECLARE_WORK(name, void (*func)(void *), void *data)
is provided to declare work_struct which is initialized with the provided func and data arguments.
Also, sometimes it provides a macro to initialize a dynamically created variable such as INIT_WORK(struct work_struct *work, void (*func)(void *), void *data)
, which assigns func and data argument to the member field of work pointer.
It seems that these macros are usually defined by the core kernel components, and cannot be seen frequently in the driver code. Is there any rule or custom that define when to provide those #defined macros for declaring or initializing data structures in the Linux Kernel such as providing this interface for frequently used data structure?
And why they are provided? Is it only because to provide a way to write clean code by giving a clean interface to declare and initialize complex data structures to kernel programmers?
Is it because some data structures are internally used, but some data structures can be utilized by multiple kernel components? In other words, to hide the implementation of the data structures?