Staging: speakup: Add helper macro for spk_synth boilerplate
PATCH 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.
drivers/staging/speakup/speakup_audptr.c | 12 +----------- drivers/staging/speakup/spk_types.h | 17 +++++++++++++++++ 2 files changed, 18 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 +17 -0
@@ -179,6 +179,23 @@ struct spk_synth {struct attribute_group attributes; }; +/* module_spk_synth() - Helper macro for speakup drivers that don't +* 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) \ +static int __init __spk_synth##_init(void) \ +{ \ + return synth_add(&(__spk_synth)); \ +} \ +module_init(__spk_synth##_init); \ +static void __exit __spk_synth##_exit(void) \ +{ \ + synth_remove(&(__spk_synth)); \ +} \ +module_exit(__spk_synth##_exit); +struct speakup_info_t {spinlock_t spinlock;int port_tts;
Signature · 1 line
1.9.1
Greg KH
maintainerQuoted 59 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.drivers/staging/speakup/speakup_audptr.c | 12 +----------- drivers/staging/speakup/spk_types.h | 17 +++++++++++++++++ 2 files changed, 18 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 +7
-0@@ -179,6 +179,23 @@ struct spk_synth {struct attribute_group attributes; }; +/* module_spk_synth() - Helper macro for speakup drivers that don't +* 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) \ +static int __init __spk_synth##_init(void) \
drivers/staging/speakup/spk_types.h struct spk_synth { · line 198
Quoted 10 lines
drivers/staging/speakup/spk_types.h +10
-0+{ \ +return synth_add (&(__spk_synth)); \ +} \ +module_init(__spk_synth##_init); \ +static void __exit __spk_synth##_exit(void) \ +{ \ +synth_remove (&(__spk_synth)); \ +} \ +module_exit(__spk_synth##_exit); +
Can't you use the module_driver() macro here instead of "rolling your own"? Look at how module_usb_driver() is defined as an example.
thanks,
greg k-h
Quoted 65 lines · Greg KH
Quoted 64 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.drivers/staging/speakup/speakup_audptr.c | 12 +----------- drivers/staging/speakup/spk_types.h | 17 +++++++++++++++++ 2 files changed, 18 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@@ -179,6 +179,23 @@ struct spk_synth {struct attribute_group attributes; }; +/* module_spk_synth() - Helper macro for speakup drivers that don't +* 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) \ +static int __init __spk_synth##_init(void) \ +{ \ + return synth_add(&(__spk_synth)); \ +} \ +module_init(__spk_synth##_init); \ +static void __exit __spk_synth##_exit(void) \
Quoted 8 lines
drivers/staging/speakup/spk_types.h struct spk_synth { · line 198
Quoted 5 lines
drivers/staging/speakup/spk_types.h +5
-0+{ \ +synth_remove (&(__spk_synth)); \ +} \ +module_exit(__spk_synth##_exit); +Can't you use the
module_driver()macro here instead of "rolling your own"? Look at howmodule_usb_driver()is defined as an example.
Yes. I guess here I can use module_driver(). I will send revised version with this change.
Thank You.
Quoted 3 lines
thanks,
greg k-h
Signature · 1 line
Vaishali