diff options
author | PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> | 2016-08-25 22:30:49 +0530 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-08-31 14:12:35 +0200 |
commit | ca75d601b5942e8cf5eed68f308be0526d0dac5d (patch) | |
tree | ca411c99f5715a5976eb942a061dfa3b2b6e841d /include | |
parent | 832c8232dd7be4977ae9fb9c7cbc4decce19a8fc (diff) | |
download | lwn-ca75d601b5942e8cf5eed68f308be0526d0dac5d.tar.gz lwn-ca75d601b5942e8cf5eed68f308be0526d0dac5d.zip |
miscdevice: Add helper macro for misc device boilerplate
Many modules call misc_register and misc_deregister in its module init
and exit methods without any additional code. This ends up being
boilerplate. This patch adds helper macro module_misc_device(), that
replaces module_init()/ module_exit() with template functions.
This patch also converts drivers to use new macro.
Change since v1:
Add device.h include in miscdevice.h as module_driver macro was not
available from other include files in some architectures.
Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/miscdevice.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h index 543037465973..722698a43d79 100644 --- a/include/linux/miscdevice.h +++ b/include/linux/miscdevice.h @@ -3,6 +3,7 @@ #include <linux/major.h> #include <linux/list.h> #include <linux/types.h> +#include <linux/device.h> /* * These allocations are managed by device@lanana.org. If you use an @@ -70,6 +71,13 @@ struct miscdevice { extern int misc_register(struct miscdevice *misc); extern void misc_deregister(struct miscdevice *misc); +/* + * Helper macro for drivers that don't do anything special in module init / exit + * call. This helps in eleminating of boilerplate code. + */ +#define module_misc_device(__misc_device) \ + module_driver(__misc_device, misc_register, misc_deregister) + #define MODULE_ALIAS_MISCDEV(minor) \ MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR) \ "-" __stringify(minor)) |