All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate
@ 2016-08-21  6:49 PrasannaKumar Muralidharan
  2016-08-21  6:49 ` [PATCH 2/2] miscdevice: Use module_misc_device() macro PrasannaKumar Muralidharan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: PrasannaKumar Muralidharan @ 2016-08-21  6:49 UTC (permalink / raw)
  To: linux, realmz6, jdike, richard, marcel, gustavo, johan.hedberg,
	arnd, gregkh, dh.herrmann, jikos, benjamin.tissoires,
	dmitry.torokhov, mb, schwidefsky, heiko.carstens, mst, elias.vds,
	akpm, jcliang, holzheu, linux-kernel
  Cc: PrasannaKumar Muralidharan

For modules that call misc_register and misc_deregister in its module
init and exit methods without any additional code 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.

Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
---
 arch/arm/common/bL_switcher_dummy_if.c | 14 +-------------
 arch/blackfin/mach-bf561/coreb.c       | 13 +------------
 drivers/hid/uhid.c                     | 13 +------------
 drivers/input/misc/uinput.c            | 15 ++-------------
 drivers/s390/char/sclp_ctl.c           | 19 +------------------
 drivers/vhost/test.c                   | 13 +------------
 include/linux/miscdevice.h             |  7 +++++++
 7 files changed, 14 insertions(+), 80 deletions(-)

diff --git a/arch/arm/common/bL_switcher_dummy_if.c b/arch/arm/common/bL_switcher_dummy_if.c
index 3f47f12..6053f64 100644
--- a/arch/arm/common/bL_switcher_dummy_if.c
+++ b/arch/arm/common/bL_switcher_dummy_if.c
@@ -56,16 +56,4 @@ static struct miscdevice bL_switcher_device = {
 	"b.L_switcher",
 	&bL_switcher_fops
 };
-
-static int __init bL_switcher_dummy_if_init(void)
-{
-	return misc_register(&bL_switcher_device);
-}
-
-static void __exit bL_switcher_dummy_if_exit(void)
-{
-	misc_deregister(&bL_switcher_device);
-}
-
-module_init(bL_switcher_dummy_if_init);
-module_exit(bL_switcher_dummy_if_exit);
+module_misc_device(bL_switcher_device);
diff --git a/arch/blackfin/mach-bf561/coreb.c b/arch/blackfin/mach-bf561/coreb.c
index 78ecb50..8a2543c 100644
--- a/arch/blackfin/mach-bf561/coreb.c
+++ b/arch/blackfin/mach-bf561/coreb.c
@@ -59,18 +59,7 @@ static struct miscdevice coreb_dev = {
 	.name  = "coreb",
 	.fops  = &coreb_fops,
 };
-
-static int __init bf561_coreb_init(void)
-{
-	return misc_register(&coreb_dev);
-}
-module_init(bf561_coreb_init);
-
-static void __exit bf561_coreb_exit(void)
-{
-	misc_deregister(&coreb_dev);
-}
-module_exit(bf561_coreb_exit);
+module_misc_device(coreb_dev);
 
 MODULE_AUTHOR("Bas Vermeulen <bvermeul@blackstar.xs4all.nl>");
 MODULE_DESCRIPTION("BF561 Core B Support");
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 99ec3ff..7f8ff39 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -779,19 +779,8 @@ static struct miscdevice uhid_misc = {
 	.minor		= UHID_MINOR,
 	.name		= UHID_NAME,
 };
+module_misc_device(uhid_misc);
 
-static int __init uhid_init(void)
-{
-	return misc_register(&uhid_misc);
-}
-
-static void __exit uhid_exit(void)
-{
-	misc_deregister(&uhid_misc);
-}
-
-module_init(uhid_init);
-module_exit(uhid_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
 MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 65ebbd1..92595b9 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -1013,23 +1013,12 @@ static struct miscdevice uinput_misc = {
 	.minor		= UINPUT_MINOR,
 	.name		= UINPUT_NAME,
 };
+module_misc_device(uinput_misc);
+
 MODULE_ALIAS_MISCDEV(UINPUT_MINOR);
 MODULE_ALIAS("devname:" UINPUT_NAME);
 
-static int __init uinput_init(void)
-{
-	return misc_register(&uinput_misc);
-}
-
-static void __exit uinput_exit(void)
-{
-	misc_deregister(&uinput_misc);
-}
-
 MODULE_AUTHOR("Aristeu Sergio Rozanski Filho");
 MODULE_DESCRIPTION("User level driver support for input subsystem");
 MODULE_LICENSE("GPL");
 MODULE_VERSION("0.3");
-
-module_init(uinput_init);
-module_exit(uinput_exit);
diff --git a/drivers/s390/char/sclp_ctl.c b/drivers/s390/char/sclp_ctl.c
index ea607a4..554eaa1 100644
--- a/drivers/s390/char/sclp_ctl.c
+++ b/drivers/s390/char/sclp_ctl.c
@@ -126,21 +126,4 @@ static struct miscdevice sclp_ctl_device = {
 	.name = "sclp",
 	.fops = &sclp_ctl_fops,
 };
-
-/*
- * Register sclp_ctl misc device
- */
-static int __init sclp_ctl_init(void)
-{
-	return misc_register(&sclp_ctl_device);
-}
-module_init(sclp_ctl_init);
-
-/*
- * Deregister sclp_ctl misc device
- */
-static void __exit sclp_ctl_exit(void)
-{
-	misc_deregister(&sclp_ctl_device);
-}
-module_exit(sclp_ctl_exit);
+module_misc_device(sclp_ctl_device);
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 97fb2f8..3cc98c0 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -322,18 +322,7 @@ static struct miscdevice vhost_test_misc = {
 	"vhost-test",
 	&vhost_test_fops,
 };
-
-static int vhost_test_init(void)
-{
-	return misc_register(&vhost_test_misc);
-}
-module_init(vhost_test_init);
-
-static void vhost_test_exit(void)
-{
-	misc_deregister(&vhost_test_misc);
-}
-module_exit(vhost_test_exit);
+module_misc_device(vhost_test_misc);
 
 MODULE_VERSION("0.0.1");
 MODULE_LICENSE("GPL v2");
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 5430374..9f32990 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -70,6 +70,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))
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] miscdevice: Use module_misc_device() macro
  2016-08-21  6:49 [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate PrasannaKumar Muralidharan
@ 2016-08-21  6:49 ` PrasannaKumar Muralidharan
  2016-08-22  8:50 ` [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate kbuild test robot
  2016-08-23 22:19 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: PrasannaKumar Muralidharan @ 2016-08-21  6:49 UTC (permalink / raw)
  To: linux, realmz6, jdike, richard, marcel, gustavo, johan.hedberg,
	arnd, gregkh, dh.herrmann, jikos, benjamin.tissoires,
	dmitry.torokhov, mb, schwidefsky, heiko.carstens, mst, elias.vds,
	akpm, jcliang, holzheu, linux-kernel
  Cc: PrasannaKumar Muralidharan

This patch removes module_init()/module_exit() from driver code by using
module_misc_device() macro.

This patch removes print statements in module init method, so it is sent
as a separate patch. If print statements are necessary this patch can be
dropped entirely.

Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
---
 arch/um/drivers/harddog_kern.c | 25 +------------------------
 drivers/bluetooth/hci_vhci.c   | 16 +---------------
 drivers/char/bfin-otp.c        | 40 +---------------------------------------
 drivers/lightnvm/core.c        | 19 +------------------
 4 files changed, 4 insertions(+), 96 deletions(-)

diff --git a/arch/um/drivers/harddog_kern.c b/arch/um/drivers/harddog_kern.c
index 2d0266d..3282787 100644
--- a/arch/um/drivers/harddog_kern.c
+++ b/arch/um/drivers/harddog_kern.c
@@ -175,27 +175,4 @@ static struct miscdevice harddog_miscdev = {
 	.name		= "watchdog",
 	.fops		= &harddog_fops,
 };
-
-static char banner[] __initdata = KERN_INFO "UML Watchdog Timer\n";
-
-static int __init harddog_init(void)
-{
-	int ret;
-
-	ret = misc_register(&harddog_miscdev);
-
-	if (ret)
-		return ret;
-
-	printk(banner);
-
-	return 0;
-}
-
-static void __exit harddog_exit(void)
-{
-	misc_deregister(&harddog_miscdev);
-}
-
-module_init(harddog_init);
-module_exit(harddog_exit);
+module_misc_device(harddog_miscdev);
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 3ff229b..c4a75a1 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -377,21 +377,7 @@ static struct miscdevice vhci_miscdev = {
 	.fops	= &vhci_fops,
 	.minor	= VHCI_MINOR,
 };
-
-static int __init vhci_init(void)
-{
-	BT_INFO("Virtual HCI driver ver %s", VERSION);
-
-	return misc_register(&vhci_miscdev);
-}
-
-static void __exit vhci_exit(void)
-{
-	misc_deregister(&vhci_miscdev);
-}
-
-module_init(vhci_init);
-module_exit(vhci_exit);
+module_misc_device(vhci_miscdev);
 
 module_param(amp, bool, 0644);
 MODULE_PARM_DESC(amp, "Create AMP controller device");
diff --git a/drivers/char/bfin-otp.c b/drivers/char/bfin-otp.c
index 44660f1..35d46da 100644
--- a/drivers/char/bfin-otp.c
+++ b/drivers/char/bfin-otp.c
@@ -230,45 +230,7 @@ static struct miscdevice bfin_otp_misc_device = {
 	.name     = DRIVER_NAME,
 	.fops     = &bfin_otp_fops,
 };
-
-/**
- *	bfin_otp_init - Initialize module
- *
- *	Registers the device and notifier handler. Actual device
- *	initialization is handled by bfin_otp_open().
- */
-static int __init bfin_otp_init(void)
-{
-	int ret;
-
-	stampit();
-
-	ret = misc_register(&bfin_otp_misc_device);
-	if (ret) {
-		pr_init(KERN_ERR PFX "unable to register a misc device\n");
-		return ret;
-	}
-
-	pr_init(KERN_INFO PFX "initialized\n");
-
-	return 0;
-}
-
-/**
- *	bfin_otp_exit - Deinitialize module
- *
- *	Unregisters the device and notifier handler. Actual device
- *	deinitialization is handled by bfin_otp_close().
- */
-static void __exit bfin_otp_exit(void)
-{
-	stampit();
-
-	misc_deregister(&bfin_otp_misc_device);
-}
-
-module_init(bfin_otp_init);
-module_exit(bfin_otp_exit);
+module_misc_device(bfin_otp_misc_device);
 
 MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>");
 MODULE_DESCRIPTION("Blackfin OTP Memory Interface");
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 9ebd2cf..c784ddc 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -1171,27 +1171,10 @@ static struct miscdevice _nvm_misc = {
 	.nodename	= "lightnvm/control",
 	.fops		= &_ctl_fops,
 };
+module_misc_device(_nvm_misc);
 
 MODULE_ALIAS_MISCDEV(MISC_DYNAMIC_MINOR);
 
-static int __init nvm_mod_init(void)
-{
-	int ret;
-
-	ret = misc_register(&_nvm_misc);
-	if (ret)
-		pr_err("nvm: misc_register failed for control device");
-
-	return ret;
-}
-
-static void __exit nvm_mod_exit(void)
-{
-	misc_deregister(&_nvm_misc);
-}
-
 MODULE_AUTHOR("Matias Bjorling <m@bjorling.me>");
 MODULE_LICENSE("GPL v2");
 MODULE_VERSION("0.1");
-module_init(nvm_mod_init);
-module_exit(nvm_mod_exit);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate
  2016-08-21  6:49 [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate PrasannaKumar Muralidharan
  2016-08-21  6:49 ` [PATCH 2/2] miscdevice: Use module_misc_device() macro PrasannaKumar Muralidharan
@ 2016-08-22  8:50 ` kbuild test robot
  2016-08-23 22:19 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2016-08-22  8:50 UTC (permalink / raw)
  To: PrasannaKumar Muralidharan
  Cc: kbuild-all, linux, realmz6, jdike, richard, marcel, gustavo,
	johan.hedberg, arnd, gregkh, dh.herrmann, jikos,
	benjamin.tissoires, dmitry.torokhov, mb, schwidefsky,
	heiko.carstens, mst, elias.vds, akpm, jcliang, holzheu,
	linux-kernel, PrasannaKumar Muralidharan

[-- Attachment #1: Type: text/plain, Size: 2643 bytes --]

Hi PrasannaKumar,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.8-rc3 next-20160822]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/PrasannaKumar-Muralidharan/drivercore-Add-helper-macro-for-misc-device-boilerplate/20160821-151236
config: s390-allyesconfig (attached as .config)
compiler: s390x-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=s390 

All error/warnings (new ones prefixed by >>):

   In file included from drivers/s390/char/sclp_ctl.c:11:0:
>> include/linux/miscdevice.h:78:2: warning: data definition has no type or storage class
     module_driver(__misc_device, misc_register, misc_deregister)
     ^
>> drivers/s390/char/sclp_ctl.c:129:1: note: in expansion of macro 'module_misc_device'
    module_misc_device(sclp_ctl_device);
    ^
>> include/linux/miscdevice.h:78:2: error: type defaults to 'int' in declaration of 'module_driver' [-Werror=implicit-int]
     module_driver(__misc_device, misc_register, misc_deregister)
     ^
>> drivers/s390/char/sclp_ctl.c:129:1: note: in expansion of macro 'module_misc_device'
    module_misc_device(sclp_ctl_device);
    ^
>> drivers/s390/char/sclp_ctl.c:129:1: warning: parameter names (without types) in function declaration
>> drivers/s390/char/sclp_ctl.c:124:26: warning: 'sclp_ctl_device' defined but not used [-Wunused-variable]
    static struct miscdevice sclp_ctl_device = {
                             ^
   cc1: some warnings being treated as errors

vim +78 include/linux/miscdevice.h

    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)
    79	
    80	#define MODULE_ALIAS_MISCDEV(minor)				\
    81		MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)	\

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 42397 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate
  2016-08-21  6:49 [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate PrasannaKumar Muralidharan
  2016-08-21  6:49 ` [PATCH 2/2] miscdevice: Use module_misc_device() macro PrasannaKumar Muralidharan
  2016-08-22  8:50 ` [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate kbuild test robot
@ 2016-08-23 22:19 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2016-08-23 22:19 UTC (permalink / raw)
  To: PrasannaKumar Muralidharan
  Cc: kbuild-all, linux, realmz6, jdike, richard, marcel, gustavo,
	johan.hedberg, arnd, gregkh, dh.herrmann, jikos,
	benjamin.tissoires, dmitry.torokhov, mb, schwidefsky,
	heiko.carstens, mst, elias.vds, akpm, jcliang, holzheu,
	linux-kernel, PrasannaKumar Muralidharan

[-- Attachment #1: Type: text/plain, Size: 3669 bytes --]

Hi PrasannaKumar,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.8-rc3 next-20160823]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/PrasannaKumar-Muralidharan/drivercore-Add-helper-macro-for-misc-device-boilerplate/20160821-151236
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All warnings (new ones prefixed by >>):

   In file included from arch/arm/common/bL_switcher_dummy_if.c:17:0:
   include/linux/miscdevice.h:78:2: warning: data definition has no type or storage class
     module_driver(__misc_device, misc_register, misc_deregister)
     ^
>> arch/arm/common/bL_switcher_dummy_if.c:59:1: note: in expansion of macro 'module_misc_device'
    module_misc_device(bL_switcher_device);
    ^
   include/linux/miscdevice.h:78:2: error: type defaults to 'int' in declaration of 'module_driver' [-Werror=implicit-int]
     module_driver(__misc_device, misc_register, misc_deregister)
     ^
>> arch/arm/common/bL_switcher_dummy_if.c:59:1: note: in expansion of macro 'module_misc_device'
    module_misc_device(bL_switcher_device);
    ^
>> arch/arm/common/bL_switcher_dummy_if.c:59:1: warning: parameter names (without types) in function declaration
>> arch/arm/common/bL_switcher_dummy_if.c:54:26: warning: 'bL_switcher_device' defined but not used [-Wunused-variable]
    static struct miscdevice bL_switcher_device = {
                             ^
   cc1: some warnings being treated as errors

vim +/module_misc_device +59 arch/arm/common/bL_switcher_dummy_if.c

    11	 * published by the Free Software Foundation.
    12	 */
    13	
    14	#include <linux/init.h>
    15	#include <linux/module.h>
    16	#include <linux/fs.h>
  > 17	#include <linux/miscdevice.h>
    18	#include <asm/uaccess.h>
    19	#include <asm/bL_switcher.h>
    20	
    21	static ssize_t bL_switcher_write(struct file *file, const char __user *buf,
    22				size_t len, loff_t *pos)
    23	{
    24		unsigned char val[3];
    25		unsigned int cpu, cluster;
    26		int ret;
    27	
    28		pr_debug("%s\n", __func__);
    29	
    30		if (len < 3)
    31			return -EINVAL;
    32	
    33		if (copy_from_user(val, buf, 3))
    34			return -EFAULT;
    35	
    36		/* format: <cpu#>,<cluster#> */
    37		if (val[0] < '0' || val[0] > '9' ||
    38		    val[1] != ',' ||
    39		    val[2] < '0' || val[2] > '1')
    40			return -EINVAL;
    41	
    42		cpu = val[0] - '0';
    43		cluster = val[2] - '0';
    44		ret = bL_switch_request(cpu, cluster);
    45	
    46		return ret ? : len;
    47	}
    48	
    49	static const struct file_operations bL_switcher_fops = {
    50		.write		= bL_switcher_write,
    51		.owner	= THIS_MODULE,
    52	};
    53	
  > 54	static struct miscdevice bL_switcher_device = {
    55		MISC_DYNAMIC_MINOR,
    56		"b.L_switcher",
    57		&bL_switcher_fops
    58	};
  > 59	module_misc_device(bL_switcher_device);

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 58535 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-23 22:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-21  6:49 [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate PrasannaKumar Muralidharan
2016-08-21  6:49 ` [PATCH 2/2] miscdevice: Use module_misc_device() macro PrasannaKumar Muralidharan
2016-08-22  8:50 ` [PATCH 1/2] drivercore: Add helper macro for misc device boilerplate kbuild test robot
2016-08-23 22:19 ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.