Skip to contentSkip to conversation

Add helper macro for pnp_register_driver boilerplate

PATCH In review Peter Huewe 2 participants 10 messages Mar 16, 2015 – Mar 18, 2015

Subsystems (10)
lore
Share & tools
lore

Peter Huewe

author maintainer
#0 lore raw

cover Add helper macro for pnp_register_driver boilerplate

This patchset introduces the module_pnp_driver macro which is a convenience macro for PNP driver modules similar to module_pci_driver and convert the affected drivers to the new helper macro.
It is intended to be used by drivers which init/exit section does nothing but register/unregister the PNP driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PNP driver.

If easier you can pull directly from my tree:

The following changes since commit 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda:

Linux 4.0-rc4 (2015-03-15 17:38:20 -0700)

are available in the git repository at:

https://github.com/PeterHuewe/linux-tpmdd.git module_pnp_driver

for you to fetch changes up to 5bf9cf2fdc9f22c7caa1c17a7eb2e17aab099b51:

pnp: tty/serial/8250/8250_fintek: Use module_pnp_driver to register driver (2015-03-16 21:40:05 +0100)

----------------------------------------------------------------

Peter Huewe (8):
pnp: Add helper macro for pnp_register_driver boilerplate
pnp: tpm/tpm_infineon: Use module_pnp_driver to register driver
pnp: ata/pata_isapnp: Use module_pnp_driver to register driver
pnp: ide/ide-pnp: Use module_pnp_driver to register driver
pnp: media/rc: Use module_pnp_driver to register driver
pnp: net/sb1000: Use module_pnp_driver to register driver
pnp: platform/x86/apple-gmux: Use module_pnp_driver to register driver
pnp: tty/serial/8250/8250_fintek: Use module_pnp_driver to register
driver

 drivers/ata/pata_isapnp.c             | 14 +-------------
 drivers/char/tpm/tpm_infineon.c       | 13 +------------
 drivers/ide/ide-pnp.c                 | 14 +-------------
 drivers/media/rc/ene_ir.c             | 13 +------------
 drivers/media/rc/fintek-cir.c         | 13 +------------
 drivers/media/rc/ite-cir.c            | 13 +------------
 drivers/media/rc/nuvoton-cir.c        | 13 +------------
 drivers/net/sb1000.c                  | 15 +--------------
 drivers/platform/x86/apple-gmux.c     | 14 +-------------
 drivers/tty/serial/8250/8250_fintek.c | 13 +------------
 include/linux/pnp.h                   | 12 ++++++++++++
 11 files changed, 22 insertions(+), 125 deletions(-)
Signature · 1 line
2.0.5
author maintainer
#1 lore raw

PATCH 1/8 pnp: Add helper macro for pnp_register_driver boilerplate

This patch introduces the module_pnp_driver macro which is a convenience macro for PNP driver modules similar to module_pci_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the PNP driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PNP driver.

Based on work done by Lars-Peter Clausen <[email protected]> for other busses (i2c and spi) and Greg KH for PCI.

Cc Lars-Peter Clausen <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 include/linux/pnp.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/pnp.h +12 -0
index 6512e9cbc6d5..5df733b8f704 100644
@@ -510,4 +510,16 @@ static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
 
 #endif /* CONFIG_PNP */
 
+/**
+ * module_pnp_driver() - Helper macro for registering a PnP driver
+ * @__pnp_driver: pnp_driver struct
+ *
+ * Helper macro for PnP drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_pnp_driver(__pnp_driver) \
+	module_driver(__pnp_driver, pnp_register_driver, \
+				    pnp_unregister_driver)
+
 #endif /* _LINUX_PNP_H */
Signature · 1 line
2.0.5
author maintainer
#2 lore raw

PATCH 2/8 pnp: tpm/tpm_infineon: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/char/tpm/tpm_infineon.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/char/tpm/tpm_infineon.c +1 -12
index 6d492132ad2b..29ba520ac24d 100644
@@ -637,18 +637,7 @@ static struct pnp_driver tpm_inf_pnp_driver = {
 	.remove = tpm_inf_pnp_remove
 };
 
-static int __init init_inf(void)
-{
-	return pnp_register_driver(&tpm_inf_pnp_driver);
-}
-
-static void __exit cleanup_inf(void)
-{
-	pnp_unregister_driver(&tpm_inf_pnp_driver);
-}
-
-module_init(init_inf);
-module_exit(cleanup_inf);
+module_pnp_driver(tpm_inf_pnp_driver);
 
 MODULE_AUTHOR("Marcel Selhorst <[email protected]>");
 MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2");
Signature · 1 line
2.0.5
author maintainer
#3 lore raw

PATCH 3/8 pnp: ata/pata_isapnp: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/ata/pata_isapnp.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/ata/pata_isapnp.c +1 -13
index b33d1f99b3a4..994f168b54a8 100644
@@ -128,20 +128,8 @@ static struct pnp_driver isapnp_driver = {
 	.remove		= isapnp_remove_one,
 };
 
-static int __init isapnp_init(void)
-{
-	return pnp_register_driver(&isapnp_driver);
-}
-
-static void __exit isapnp_exit(void)
-{
-	pnp_unregister_driver(&isapnp_driver);
-}
-
+module_pnp_driver(isapnp_driver);
 MODULE_AUTHOR("Alan Cox");
 MODULE_DESCRIPTION("low-level driver for ISA PnP ATA");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
-
-module_init(isapnp_init);
-module_exit(isapnp_exit);
Signature · 1 line
2.0.5
author maintainer
#4 lore raw

PATCH 4/8 pnp: ide/ide-pnp: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/ide/ide-pnp.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/ide/ide-pnp.c +1 -13
index e5f3db831373..f5f2b62471da 100644
@@ -96,17 +96,5 @@ static struct pnp_driver idepnp_driver = {
 	.remove		= idepnp_remove,
 };
 
-static int __init pnpide_init(void)
-{
-	return pnp_register_driver(&idepnp_driver);
-}
-
-static void __exit pnpide_exit(void)
-{
-	pnp_unregister_driver(&idepnp_driver);
-}
-
-module_init(pnpide_init);
-module_exit(pnpide_exit);
-
+module_pnp_driver(idepnp_driver);
 MODULE_LICENSE("GPL");
Signature · 1 line
2.0.5
author maintainer
#5 lore raw

PATCH 5/8 pnp: media/rc: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/media/rc/ene_ir.c      | 13 +------------
 drivers/media/rc/fintek-cir.c  | 13 +------------
 drivers/media/rc/ite-cir.c     | 13 +------------
 drivers/media/rc/nuvoton-cir.c | 13 +------------
 4 files changed, 4 insertions(+), 48 deletions(-)
drivers/media/rc/ene_ir.c +1 -12
index e80f2c6c5f1a..8d77e1c4a141 100644
@@ -1195,16 +1195,6 @@ static struct pnp_driver ene_driver = {
 	.shutdown = ene_shutdown,
 };
 
-static int __init ene_init(void)
-{
-	return pnp_register_driver(&ene_driver);
-}
-
-static void ene_exit(void)
-{
-	pnp_unregister_driver(&ene_driver);
-}
-
 module_param(sample_period, int, S_IRUGO);
 MODULE_PARM_DESC(sample_period, "Hardware sample period (50 us default)");
 
@@ -1226,5 +1216,4 @@ MODULE_DESCRIPTION
 MODULE_AUTHOR("Maxim Levitsky");
 MODULE_LICENSE("GPL");
 
-module_init(ene_init);
-module_exit(ene_exit);
+module_pnp_driver(ene_driver);
drivers/media/rc/fintek-cir.c +1 -12
index b5167573240e..5c63c2ec6183 100644
@@ -684,16 +684,6 @@ static struct pnp_driver fintek_driver = {
 	.shutdown	= fintek_shutdown,
 };
 
-static int __init fintek_init(void)
-{
-	return pnp_register_driver(&fintek_driver);
-}
-
-static void __exit fintek_exit(void)
-{
-	pnp_unregister_driver(&fintek_driver);
-}
-
 module_param(debug, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Enable debugging output");
 
@@ -703,5 +693,4 @@ MODULE_DESCRIPTION(FINTEK_DESCRIPTION " driver");
 MODULE_AUTHOR("Jarod Wilson <[email protected]>");
 MODULE_LICENSE("GPL");
 
-module_init(fintek_init);
-module_exit(fintek_exit);
+module_pnp_driver(fintek_driver);
drivers/media/rc/ite-cir.c +1 -12
index 56abf9120cc2..0f301903aa6f 100644
@@ -1708,21 +1708,10 @@ static struct pnp_driver ite_driver = {
 	.shutdown	= ite_shutdown,
 };
 
-static int __init ite_init(void)
-{
-	return pnp_register_driver(&ite_driver);
-}
-
-static void __exit ite_exit(void)
-{
-	pnp_unregister_driver(&ite_driver);
-}
-
 MODULE_DEVICE_TABLE(pnp, ite_ids);
 MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
 
 MODULE_AUTHOR("Juan J. Garcia de Soria <[email protected]>");
 MODULE_LICENSE("GPL");
 
-module_init(ite_init);
-module_exit(ite_exit);
+module_pnp_driver(ite_driver);
drivers/media/rc/nuvoton-cir.c +1 -12
index 9c2c8635ff33..85af7a869167 100644
@@ -1219,16 +1219,6 @@ static struct pnp_driver nvt_driver = {
 	.shutdown	= nvt_shutdown,
 };
 
-static int __init nvt_init(void)
-{
-	return pnp_register_driver(&nvt_driver);
-}
-
-static void __exit nvt_exit(void)
-{
-	pnp_unregister_driver(&nvt_driver);
-}
-
 module_param(debug, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Enable debugging output");
 
@@ -1238,5 +1228,4 @@ MODULE_DESCRIPTION("Nuvoton W83667HG-A & W83677HG-I CIR driver");
 MODULE_AUTHOR("Jarod Wilson <[email protected]>");
 MODULE_LICENSE("GPL");
 
-module_init(nvt_init);
-module_exit(nvt_exit);
+module_pnp_driver(nvt_driver);
Signature · 1 line
2.0.5
author maintainer
#6 lore raw

PATCH 6/8 pnp: net/sb1000: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/net/sb1000.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/net/sb1000.c +1 -14
index 66c2f1a01963..aad0b59d41e3 100644
@@ -1175,17 +1175,4 @@ MODULE_AUTHOR("Franco Venturi <[email protected]>");
 MODULE_DESCRIPTION("General Instruments SB1000 driver");
 MODULE_LICENSE("GPL");
 
-static int __init
-sb1000_init(void)
-{
-	return pnp_register_driver(&sb1000_driver);
-}
-
-static void __exit
-sb1000_exit(void)
-{
-	pnp_unregister_driver(&sb1000_driver);
-}
-
-module_init(sb1000_init);
-module_exit(sb1000_exit);
+module_pnp_driver(sb1000_driver);
Signature · 1 line
2.0.5
author maintainer
#7 lore raw

PATCH 7/8 pnp: platform/x86/apple-gmux: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/platform/x86/apple-gmux.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/platform/x86/apple-gmux.c +1 -13
index b9429fbf1cd8..66d6d22c239c 100644
@@ -624,19 +624,7 @@ static struct pnp_driver gmux_pnp_driver = {
 	},
 };
 
-static int __init apple_gmux_init(void)
-{
-	return pnp_register_driver(&gmux_pnp_driver);
-}
-
-static void __exit apple_gmux_exit(void)
-{
-	pnp_unregister_driver(&gmux_pnp_driver);
-}
-
-module_init(apple_gmux_init);
-module_exit(apple_gmux_exit);
-
+module_pnp_driver(gmux_pnp_driver);
 MODULE_AUTHOR("Seth Forshee <[email protected]>");
 MODULE_DESCRIPTION("Apple Gmux Driver");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.0.5
author maintainer
#8 lore raw

PATCH 8/8 pnp: tty/serial/8250/8250_fintek: Use module_pnp_driver to register driver

In reply to Peter Huewe

Removing some boilerplate by using module_pnp_driver instead of calling register and unregister in the otherwise empty init/exit functions

---
 drivers/tty/serial/8250/8250_fintek.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/tty/serial/8250/8250_fintek.c +1 -12
index 1e6899bc9429..5815e81b5fc6 100644
@@ -234,18 +234,7 @@ static struct pnp_driver fintek_8250_driver = {
 	.id_table	= fintek_dev_table,
 };
 
-static int fintek_8250_init(void)
-{
-	return pnp_register_driver(&fintek_8250_driver);
-}
-module_init(fintek_8250_init);
-
-static void fintek_8250_exit(void)
-{
-	pnp_unregister_driver(&fintek_8250_driver);
-}
-module_exit(fintek_8250_exit);
-
+module_pnp_driver(fintek_8250_driver);
 MODULE_DESCRIPTION("Fintek F812164 module");
 MODULE_AUTHOR("Ricardo Ribalda <[email protected]>");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.0.5
#9 lore raw
In reply to Peter Huewe
Quoted 23 lines · Peter Huewe

This patchset introduces the module_pnp_driver macro which is a convenience macro for PNP driver modules similar to module_pci_driver and convert the affected drivers to the new helper macro.
It is intended to be used by drivers which init/exit section does nothing but register/unregister the PNP driver. By using this macro it is possible to eliminate a few lines of boilerplate code per PNP driver.

If easier you can pull directly from my tree:

The following changes since commit 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda:

Linux 4.0-rc4 (2015-03-15 17:38:20 -0700)

are available in the git repository at:

https://github.com/PeterHuewe/linux-tpmdd.git module_pnp_driver

for you to fetch changes up to 5bf9cf2fdc9f22c7caa1c17a7eb2e17aab099b51:

pnp: tty/serial/8250/8250_fintek: Use module_pnp_driver to register driver (2015-03-16 21:40:05 +0100)

----------------------------------------------------------------

Quoted 10 lines

Peter Huewe (8):
pnp: Add helper macro for pnp_register_driver boilerplate
pnp: tpm/tpm_infineon: Use module_pnp_driver to register driver
pnp: ata/pata_isapnp: Use module_pnp_driver to register driver
pnp: ide/ide-pnp: Use module_pnp_driver to register driver
pnp: media/rc: Use module_pnp_driver to register driver
pnp: net/sb1000: Use module_pnp_driver to register driver
pnp: platform/x86/apple-gmux: Use module_pnp_driver to register driver
pnp: tty/serial/8250/8250_fintek: Use module_pnp_driver to register
driver

Makes sense to me. I'll queue this up for 4.1 if there are no objections.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.