Staging: speakup: Add helper macro for spk_synth boilerplate
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
@@ -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
@@ -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
Greg KH
maintainerQuoted 17 lines · Vaishali Thakkar
For simple modules that contain a single
spk_synthwithout 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.Signed-off-by Vaishali Thakkar <[email protected]>---
v1 : Here, I know, I can go for changing all files
and make them usemodule_spk_synthat 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 : Usemodule_drivermacro 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
Quoted 19 lines · Greg KH
Quoted 17 lines · Vaishali Thakkar
For simple modules that contain a single
spk_synthwithout 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.Signed-off-by Vaishali Thakkar <[email protected]>---
v1 : Here, I know, I can go for changing all files
and make them usemodule_spk_synthat 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 : Usemodule_drivermacro 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
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
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
Greg KH
maintainerQuoted 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_driveretc. 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
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_driveretc. 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
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_driveretc. 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