Skip to contentSkip to conversation

parport: Introduce module_parport_driver() helper macro

PATCH Superseded Andy Shevchenko 2 participants 8 messages Feb 16, 2021 – Mar 2, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 parport: Introduce module_parport_driver() helper macro

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

---
v2: fixed typo in the macro

 include/linux/parport.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
include/linux/parport.h +11 -1
index 1fb508c19e83..54539b80021e 100644
@@ -301,9 +301,19 @@ int __must_check __parport_register_driver(struct parport_driver *,
 	__parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
 
 /* Unregister a high-level driver. */
-extern void parport_unregister_driver (struct parport_driver *);
 void parport_unregister_driver(struct parport_driver *);
 
+/**
+ * module_parport_driver() - Helper macro for registering a modular parport driver
+ * @__parport_driver: struct parport_driver to be used
+ *
+ * Helper macro for parport drivers which do not do anything special in module
+ * init and 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_parport_driver(__parport_driver) \
+	module_driver(__parport_driver, parport_register_driver, parport_unregister_driver)
+
 /* If parport_register_driver doesn't fit your needs, perhaps
  * parport_find_xxx does. */
 extern struct parport *parport_find_number (int);
Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 2/3 spi: butterfly: Switch to use module_parport_driver()

Switch to use module_parport_driver() to reduce boilerplate code. Note, device_initcall() is a default for module_init().

---
v2: added Ack (Mark)

 drivers/spi/spi-butterfly.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/spi/spi-butterfly.c +1 -12
index 7e71a351f3b7..cceae816cebc 100644
@@ -317,18 +317,7 @@ static struct parport_driver butterfly_driver = {
 	.detach =	butterfly_detach,
 	.devmodel = true,
 };
-
-static int __init butterfly_init(void)
-{
-	return parport_register_driver(&butterfly_driver);
-}
-device_initcall(butterfly_init);
-
-static void __exit butterfly_exit(void)
-{
-	parport_unregister_driver(&butterfly_driver);
-}
-module_exit(butterfly_exit);
+module_parport_driver(butterfly_driver);
 
 MODULE_DESCRIPTION("Parport Adapter driver for AVR Butterfly");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.30.0
#2 lore raw

PATCH v2 3/3 spi: lm70llp: Switch to use module_parport_driver()

In reply to Andy Shevchenko

Switch to use module_parport_driver() to reduce boilerplate code.

---
v2: added Ack (Mark), drop unneeded note from the commit message

 drivers/spi/spi-lm70llp.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/spi/spi-lm70llp.c +1 -12
index 174dba29b1dd..f914b8d2043e 100644
@@ -320,18 +320,7 @@ static struct parport_driver spi_lm70llp_drv = {
 	.detach =	spi_lm70llp_detach,
 	.devmodel =	true,
 };
-
-static int __init init_spi_lm70llp(void)
-{
-	return parport_register_driver(&spi_lm70llp_drv);
-}
-module_init(init_spi_lm70llp);
-
-static void __exit cleanup_spi_lm70llp(void)
-{
-	parport_unregister_driver(&spi_lm70llp_drv);
-}
-module_exit(cleanup_spi_lm70llp);
+module_parport_driver(spi_lm70llp_drv);
 
 MODULE_AUTHOR("Kaiwan N Billimoria <[email protected]>");
 MODULE_DESCRIPTION(
Signature · 1 line
2.30.0
#3 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

Sudip, any comments on this?

Quoted 34 lines

---
v2: fixed typo in the macro

 include/linux/parport.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
include/linux/parport.h +11 -1
index 1fb508c19e83..54539b80021e 100644
@@ -301,9 +301,19 @@ int __must_check __parport_register_driver(struct parport_driver *,
 	__parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
 
 /* Unregister a high-level driver. */
-extern void parport_unregister_driver (struct parport_driver *);
 void parport_unregister_driver(struct parport_driver *);
 
+/**
+ * module_parport_driver() - Helper macro for registering a modular parport driver
+ * @__parport_driver: struct parport_driver to be used
+ *
+ * Helper macro for parport drivers which do not do anything special in module
+ * init and 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_parport_driver(__parport_driver) \
+	module_driver(__parport_driver, parport_register_driver, parport_unregister_driver)
+
 /* If parport_register_driver doesn't fit your needs, perhaps
  * parport_find_xxx does. */
 extern struct parport *parport_find_number (int);
Signature · 1 line
2.30.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by
#4 lore raw

Hi Andy,

Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

Sudip, any comments on this?

Sorry for the delay in reply.
lgtm. I think there are few more drivers which can also use this new helper. Will you like to do them also?

--
Regards
Sudip

#5 lore raw
Quoted 10 lines · Sudip Mukherjee
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

Sudip, any comments on this?

Sorry for the delay in reply.
lgtm. I think there are few more drivers which can also use this new helper. Will you like to do them also?

Yes, that's the (slow going) plan.

Quoted 1 line

Thanks! I considered that you take it thru parport tree. Do you have something else in mind?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#6 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 10 lines · Sudip Mukherjee
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

Sudip, any comments on this?

Sorry for the delay in reply.
lgtm. I think there are few more drivers which can also use this new helper. Will you like to do them also?

Quoted 6 lines

Yes, that's the (slow going) plan.

Quoted 1 line

Thanks! I considered that you take it thru parport tree. Do you have something else in mind?

I dont have a separate parport tree (parport is not under active development to have a separate tree). I send everything parport related to Greg and then he adds it to his tree.
I guess in this case if Greg agrees it can go via Mark's tree as the series will also have SPI related patches.

--
Regards
Sudip

#7 lore raw
Quoted 17 lines · Sudip Mukherjee
Quoted 15 lines · Andy Shevchenko
Quoted 10 lines · Sudip Mukherjee
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Introduce module_parport_driver() helper macro to reduce boilerplate in the existing and new code.

Sudip, any comments on this?

Sorry for the delay in reply.
lgtm. I think there are few more drivers which can also use this new helper. Will you like to do them also?

Yes, that's the (slow going) plan.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Thanks! I considered that you take it thru parport tree. Do you have something else in mind?

I dont have a separate parport tree (parport is not under active development to have a separate tree). I send everything parport related to Greg and then he adds it to his tree.

MAINTAINERS doesn't show this. But good to know.

Quoted 2 lines

I guess in this case if Greg agrees it can go via Mark's tree as the series will also have SPI related patches.

Okay, if Greg wants to handle this himself, I think I have to resend (he wasn't in the Cc list). Otherwise Mark can also apply this if Greg is okay (but sounds like I have to resend anyway to let him understand what's going on here).

Signature · 2 lines
With Best Regards,
Andy Shevchenko