Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

PrasannaKumar Muralidharan and committed by
Greg Kroah-Hartman
ca75d601 832c8232

+15 -80
+1 -13
arch/arm/common/bL_switcher_dummy_if.c
··· 56 56 "b.L_switcher", 57 57 &bL_switcher_fops 58 58 }; 59 - 60 - static int __init bL_switcher_dummy_if_init(void) 61 - { 62 - return misc_register(&bL_switcher_device); 63 - } 64 - 65 - static void __exit bL_switcher_dummy_if_exit(void) 66 - { 67 - misc_deregister(&bL_switcher_device); 68 - } 69 - 70 - module_init(bL_switcher_dummy_if_init); 71 - module_exit(bL_switcher_dummy_if_exit); 59 + module_misc_device(bL_switcher_device);
+1 -12
arch/blackfin/mach-bf561/coreb.c
··· 59 59 .name = "coreb", 60 60 .fops = &coreb_fops, 61 61 }; 62 - 63 - static int __init bf561_coreb_init(void) 64 - { 65 - return misc_register(&coreb_dev); 66 - } 67 - module_init(bf561_coreb_init); 68 - 69 - static void __exit bf561_coreb_exit(void) 70 - { 71 - misc_deregister(&coreb_dev); 72 - } 73 - module_exit(bf561_coreb_exit); 62 + module_misc_device(coreb_dev); 74 63 75 64 MODULE_AUTHOR("Bas Vermeulen <bvermeul@blackstar.xs4all.nl>"); 76 65 MODULE_DESCRIPTION("BF561 Core B Support");
+1 -12
drivers/hid/uhid.c
··· 779 779 .minor = UHID_MINOR, 780 780 .name = UHID_NAME, 781 781 }; 782 + module_misc_device(uhid_misc); 782 783 783 - static int __init uhid_init(void) 784 - { 785 - return misc_register(&uhid_misc); 786 - } 787 - 788 - static void __exit uhid_exit(void) 789 - { 790 - misc_deregister(&uhid_misc); 791 - } 792 - 793 - module_init(uhid_init); 794 - module_exit(uhid_exit); 795 784 MODULE_LICENSE("GPL"); 796 785 MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); 797 786 MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
+2 -13
drivers/input/misc/uinput.c
··· 1013 1013 .minor = UINPUT_MINOR, 1014 1014 .name = UINPUT_NAME, 1015 1015 }; 1016 + module_misc_device(uinput_misc); 1017 + 1016 1018 MODULE_ALIAS_MISCDEV(UINPUT_MINOR); 1017 1019 MODULE_ALIAS("devname:" UINPUT_NAME); 1018 - 1019 - static int __init uinput_init(void) 1020 - { 1021 - return misc_register(&uinput_misc); 1022 - } 1023 - 1024 - static void __exit uinput_exit(void) 1025 - { 1026 - misc_deregister(&uinput_misc); 1027 - } 1028 1020 1029 1021 MODULE_AUTHOR("Aristeu Sergio Rozanski Filho"); 1030 1022 MODULE_DESCRIPTION("User level driver support for input subsystem"); 1031 1023 MODULE_LICENSE("GPL"); 1032 1024 MODULE_VERSION("0.3"); 1033 - 1034 - module_init(uinput_init); 1035 - module_exit(uinput_exit);
+1 -18
drivers/s390/char/sclp_ctl.c
··· 126 126 .name = "sclp", 127 127 .fops = &sclp_ctl_fops, 128 128 }; 129 - 130 - /* 131 - * Register sclp_ctl misc device 132 - */ 133 - static int __init sclp_ctl_init(void) 134 - { 135 - return misc_register(&sclp_ctl_device); 136 - } 137 - module_init(sclp_ctl_init); 138 - 139 - /* 140 - * Deregister sclp_ctl misc device 141 - */ 142 - static void __exit sclp_ctl_exit(void) 143 - { 144 - misc_deregister(&sclp_ctl_device); 145 - } 146 - module_exit(sclp_ctl_exit); 129 + module_misc_device(sclp_ctl_device);
+1 -12
drivers/vhost/test.c
··· 322 322 "vhost-test", 323 323 &vhost_test_fops, 324 324 }; 325 - 326 - static int vhost_test_init(void) 327 - { 328 - return misc_register(&vhost_test_misc); 329 - } 330 - module_init(vhost_test_init); 331 - 332 - static void vhost_test_exit(void) 333 - { 334 - misc_deregister(&vhost_test_misc); 335 - } 336 - module_exit(vhost_test_exit); 325 + module_misc_device(vhost_test_misc); 337 326 338 327 MODULE_VERSION("0.0.1"); 339 328 MODULE_LICENSE("GPL v2");
+8
include/linux/miscdevice.h
··· 3 3 #include <linux/major.h> 4 4 #include <linux/list.h> 5 5 #include <linux/types.h> 6 + #include <linux/device.h> 6 7 7 8 /* 8 9 * These allocations are managed by device@lanana.org. If you use an ··· 70 69 71 70 extern int misc_register(struct miscdevice *misc); 72 71 extern void misc_deregister(struct miscdevice *misc); 72 + 73 + /* 74 + * Helper macro for drivers that don't do anything special in module init / exit 75 + * call. This helps in eleminating of boilerplate code. 76 + */ 77 + #define module_misc_device(__misc_device) \ 78 + module_driver(__misc_device, misc_register, misc_deregister) 73 79 74 80 #define MODULE_ALIAS_MISCDEV(minor) \ 75 81 MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR) \