Skip to contentSkip to conversation

Staging: speakup: Add helper macro for spk_synth boilerplate

PATCH Superseded Vaishali Thakkar 3 participants 8 messages Mar 16, 2015 Staging

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: speakup: Add helper macro for spk_synth boilerplate

For simple modules that contain a single spk_synth without any additional setup code then ends up being a block of duplicated boilerplate. This patch adds a new macro, module_spk_synth(), which replaces the module_init()/module_exit() registrations with template functions.

---
v1 : Here, I know, I can go for changing all files
and make them use module_spk_synth at a single point. But as I am sending this patch as a sample patch, I am changing only one file to show the use of helper macro. I will go for changing all other such cases in this driver if this patch will be accepted.
v2 : Use module_driver macro in definition of helper macro

 drivers/staging/speakup/speakup_audptr.c | 12 +-----------
 drivers/staging/speakup/spk_types.h      | 12 ++++++++++++
 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/staging/speakup/speakup_audptr.c +1 -11
index 5cbaec8..ea89e36 100644
@@ -177,18 +177,8 @@ module_param_named(start, synth_audptr.startup, short, S_IRUGO);
 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
-static int __init audptr_init(void)
-{
-	return synth_add(&synth_audptr);
-}
-
-static void __exit audptr_exit(void)
-{
-	synth_remove(&synth_audptr);
-}
+module_spk_synth(synth_audptr);
 
-module_init(audptr_init);
-module_exit(audptr_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
drivers/staging/speakup/spk_types.h +12 -0
index 8c565c9..67aa5e9 100644
@@ -16,6 +16,7 @@
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
 #include <linux/io.h>		/* for inb_p, outb_p, inb, outb, etc... */
+#include <linux/device.h>	/* for struct device */
 
 enum var_type_t {
 	VAR_NUM = 0,
@@ -179,6 +180,17 @@ struct spk_synth {
 	struct attribute_group attributes;
 };
 
+/**
+ * module_spk_synth() - Helper macro for registering a speakup driver
+ * @__spk_synth: spk_synth struct
+ *
+ * Helper macro for speakup 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_spk_synth(__spk_synth) \
+	module_driver(__spk_synth, synth_add, \
+			synth_remove)
 struct speakup_info_t {
 	spinlock_t spinlock;
 	int port_tts;
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 17 lines · Vaishali Thakkar

For simple modules that contain a single spk_synth without any additional setup code then ends up being a block of duplicated boilerplate. This patch adds a new macro, module_spk_synth(), which replaces the module_init()/module_exit() registrations with template functions.

---
v1 : Here, I know, I can go for changing all files
and make them use module_spk_synth at a single point. But as I am sending this patch as a sample patch, I am changing only one file to show the use of helper macro. I will go for changing all other such cases in this driver if this patch will be accepted.
v2 : Use module_driver macro in definition of helper macro

Quoted 3 lines
 drivers/staging/speakup/speakup_audptr.c | 12 +-----------
 drivers/staging/speakup/spk_types.h      | 12 ++++++++++++
 2 files changed, 13 insertions(+), 11 deletions(-)

Please make this a patch series, the first one adding the new macro, and the rest converting all of the different modules to use it.

thanks,

greg k-h

#2 lore raw
Quoted 19 lines · Greg KH
Quoted 17 lines · Vaishali Thakkar

For simple modules that contain a single spk_synth without any additional setup code then ends up being a block of duplicated boilerplate. This patch adds a new macro, module_spk_synth(), which replaces the module_init()/module_exit() registrations with template functions.

---
v1 : Here, I know, I can go for changing all files
and make them use module_spk_synth at a single point. But as I am sending this patch as a sample patch, I am changing only one file to show the use of helper macro. I will go for changing all other such cases in this driver if this patch will be accepted.
v2 : Use module_driver macro in definition of helper macro

Quoted 6 lines
Quoted 3 lines
 drivers/staging/speakup/speakup_audptr.c | 12 +-----------
 drivers/staging/speakup/spk_types.h      | 12 ++++++++++++
 2 files changed, 13 insertions(+), 11 deletions(-)

Please make this a patch series, the first one adding the new macro, and the rest converting all of the different modules to use it.

Ok. Will do it.

Thank You

Quoted 3 lines

thanks,

greg k-h

#3 lore raw
In reply to Vaishali Thakkar

drivers/staging/speakup/spk_types.h struct spk_synth { · line 193

Quoted 3 lines
drivers/staging/speakup/spk_types.h +3 -0
+#define module_spk_synth(__spk_synth) \
+	module_driver(__spk_synth, synth_add, \
+			synth_remove)

Why the newline before synth_remove?

julia

#4 lore raw
Quoted 5 lines · Julia Lawall

drivers/staging/speakup/spk_types.h struct spk_synth { · line 193

Quoted 3 lines
drivers/staging/speakup/spk_types.h +3 -0
+#define module_spk_synth(__spk_synth) \
+     module_driver(__spk_synth, synth_add, \
+                     synth_remove)

Why the newline before synth_remove?

Just for the consistency. I followed all such macro examples like module_usb_driver, module_platform_driver, module_pci_driver etc. And I guess may be this line will go over 80 characters though I haven't checked that.

Should I go for writing like this in a single line [if it will not go beyond 80 characters]?

module_driver(__spk_synth, synth_add, synth_remove) \

Quoted 1 line

julia

Signature · 1 line
Vaishali
maintainer
#5 lore raw
Quoted 12 lines · Vaishali Thakkar
Quoted 5 lines · Julia Lawall

drivers/staging/speakup/spk_types.h struct spk_synth { · line 193

Quoted 3 lines
drivers/staging/speakup/spk_types.h +3 -0
+#define module_spk_synth(__spk_synth) \
+     module_driver(__spk_synth, synth_add, \
+                     synth_remove)

Why the newline before synth_remove?

Just for the consistency. I followed all such macro examples like module_usb_driver, module_platform_driver, module_pci_driver etc. And I guess may be this line will go over 80 characters though I haven't checked that.

Quoted 4 lines

Should I go for writing like this in a single line [if it will not go beyond 80 characters]?

module_driver(__spk_synth, synth_add, synth_remove) \

Yes, please do so, the only reason I wrapped the module_usb_driver() lines was because I had to.

thanks,

greg k-h

#6 lore raw
Quoted 13 lines · Greg KH
Quoted 12 lines · Vaishali Thakkar
Quoted 5 lines · Julia Lawall

drivers/staging/speakup/spk_types.h struct spk_synth { · line 193

Quoted 3 lines
drivers/staging/speakup/spk_types.h +3 -0
+#define module_spk_synth(__spk_synth) \
+     module_driver(__spk_synth, synth_add, \
+                     synth_remove)

Why the newline before synth_remove?

Just for the consistency. I followed all such macro examples like module_usb_driver, module_platform_driver, module_pci_driver etc. And I guess may be this line will go over 80 characters though I haven't checked that.

Quoted 7 lines
Quoted 4 lines

Should I go for writing like this in a single line [if it will not go beyond 80 characters]?

module_driver(__spk_synth, synth_add, synth_remove) \

Yes, please do so, the only reason I wrapped the module_usb_driver() lines was because I had to.

Ok. Will go for it too.

Quoted 3 lines

thanks,

greg k-h

Signature · 1 line
Vaishali
#7 lore raw
In reply to Vaishali Thakkar
Quoted 12 lines · Vaishali Thakkar
Quoted 5 lines · Julia Lawall

drivers/staging/speakup/spk_types.h struct spk_synth { · line 193

Quoted 3 lines
drivers/staging/speakup/spk_types.h +3 -0
+#define module_spk_synth(__spk_synth) \
+     module_driver(__spk_synth, synth_add, \
+                     synth_remove)

Why the newline before synth_remove?

Just for the consistency. I followed all such macro examples like module_usb_driver, module_platform_driver, module_pci_driver etc. And I guess may be this line will go over 80 characters though I haven't checked that.

Quoted 4 lines

Should I go for writing like this in a single line [if it will not go beyond 80 characters]?

module_driver(__spk_synth, synth_add, synth_remove) \

I think this will look better (without the final \).

julia