Skip to contentSkip to conversation

Staging: speakup: Introduce helper macro module_spk_synth

PATCH Superseded Vaishali Thakkar 2 participants 5 messages Mar 17, 2015 Staging

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Staging: speakup: Introduce helper macro module_spk_synth

This patch-set adds new macro module_spk_synth for simple modules that contain a single spk_synth without any additional setup code then ends up being a block of duplicated boilerplate. Macro module_spk_synth replaces module_init()/module_exit() registrations with template functions. So, patch-set also handles all such cases where module_spk_synth can be used.

Changes since v2:
- Add blank line after defining module_spk_synth

Vaishali Thakkar (2):
Staging: speakup: Add helper macro for spk_synth boilerplate
Staging: speakup: Use module_spk_synth

 drivers/staging/speakup/speakup_acntpc.c | 12 +-----------
 drivers/staging/speakup/speakup_acntsa.c | 12 +-----------
 drivers/staging/speakup/speakup_apollo.c | 12 +-----------
 drivers/staging/speakup/speakup_audptr.c | 12 +-----------
 drivers/staging/speakup/speakup_bns.c    | 12 +-----------
 drivers/staging/speakup/speakup_decext.c | 12 +-----------
 drivers/staging/speakup/speakup_decpc.c  | 12 +-----------
 drivers/staging/speakup/speakup_dectlk.c | 12 +-----------
 drivers/staging/speakup/speakup_dtlk.c   | 12 +-----------
 drivers/staging/speakup/speakup_dummy.c  | 12 +-----------
 drivers/staging/speakup/speakup_keypc.c  | 12 +-----------
 drivers/staging/speakup/speakup_ltlk.c   | 12 +-----------
 drivers/staging/speakup/speakup_soft.c   | 13 +------------
 drivers/staging/speakup/speakup_spkout.c | 12 +-----------
 drivers/staging/speakup/speakup_txprt.c  | 12 +-----------
 drivers/staging/speakup/spk_types.h      | 11 +++++++++++
 16 files changed, 26 insertions(+), 166 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/2 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.

---
Changes since v1:
- Use module_driver macro in definition of helper macro
Changes since v2:
- Correct unnecessory line wrapping of module_driver
- Split patch in to 2 patches
Changes since v3:
- Put blank line after module_spk_synth

 drivers/staging/speakup/spk_types.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/staging/speakup/spk_types.h +11 -0
index 8c565c9..38e0a3c 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,16 @@ 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
#4 lore raw

PATCH v2 2/2 Staging: speakup: Use module_spk_synth

In reply to Vaishali Thakkar

Macro module_spk_synth can be used for speakup drivers whose init and exit paths does only module registrations. So, here remove some boilerplate code by using module_spk_synth.

---
Changes since v1:
- No change but as patch is in series with another patch, send new version.

 drivers/staging/speakup/speakup_acntpc.c | 12 +-----------
 drivers/staging/speakup/speakup_acntsa.c | 12 +-----------
 drivers/staging/speakup/speakup_apollo.c | 12 +-----------
 drivers/staging/speakup/speakup_audptr.c | 12 +-----------
 drivers/staging/speakup/speakup_bns.c    | 12 +-----------
 drivers/staging/speakup/speakup_decext.c | 12 +-----------
 drivers/staging/speakup/speakup_decpc.c  | 12 +-----------
 drivers/staging/speakup/speakup_dectlk.c | 12 +-----------
 drivers/staging/speakup/speakup_dtlk.c   | 12 +-----------
 drivers/staging/speakup/speakup_dummy.c  | 12 +-----------
 drivers/staging/speakup/speakup_keypc.c  | 12 +-----------
 drivers/staging/speakup/speakup_ltlk.c   | 12 +-----------
 drivers/staging/speakup/speakup_soft.c   | 13 +------------
 drivers/staging/speakup/speakup_spkout.c | 12 +-----------
 drivers/staging/speakup/speakup_txprt.c  | 12 +-----------
 15 files changed, 15 insertions(+), 166 deletions(-)
drivers/staging/speakup/speakup_acntpc.c +1 -11
index f0bfd9e..f418893 100644
@@ -318,18 +318,8 @@ module_param_named(start, synth_acntpc.startup, short, S_IRUGO);
 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
-static int __init acntpc_init(void)
-{
-	return synth_add(&synth_acntpc);
-}
-
-static void __exit acntpc_exit(void)
-{
-	synth_remove(&synth_acntpc);
-}
+module_spk_synth(synth_acntpc);
 
-module_init(acntpc_init);
-module_exit(acntpc_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
drivers/staging/speakup/speakup_acntsa.c +1 -11
index 3f2b569..af2690f 100644
@@ -143,18 +143,8 @@ module_param_named(start, synth_acntsa.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 acntsa_init(void)
-{
-	return synth_add(&synth_acntsa);
-}
-
-static void __exit acntsa_exit(void)
-{
-	synth_remove(&synth_acntsa);
-}
+module_spk_synth(synth_acntsa);
 
-module_init(acntsa_init);
-module_exit(acntsa_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Accent SA synthesizer");
drivers/staging/speakup/speakup_apollo.c +1 -11
index 678b263..51788f7 100644
@@ -207,18 +207,8 @@ module_param_named(start, synth_apollo.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 apollo_init(void)
-{
-	return synth_add(&synth_apollo);
-}
-
-static void __exit apollo_exit(void)
-{
-	synth_remove(&synth_apollo);
-}
+module_spk_synth(synth_apollo);
 
-module_init(apollo_init);
-module_exit(apollo_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
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/speakup_bns.c +1 -11
index 2f07028..80f8358 100644
@@ -127,18 +127,8 @@ module_param_named(start, synth_bns.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 bns_init(void)
-{
-	return synth_add(&synth_bns);
-}
+module_spk_synth(synth_bns);
 
-static void __exit bns_exit(void)
-{
-	synth_remove(&synth_bns);
-}
-
-module_init(bns_init);
-module_exit(bns_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Braille 'n Speak synthesizers");
drivers/staging/speakup/speakup_decext.c +1 -11
index 5550290..2b772f8 100644
@@ -234,18 +234,8 @@ module_param_named(start, synth_decext.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 decext_init(void)
-{
-	return synth_add(&synth_decext);
-}
-
-static void __exit decext_exit(void)
-{
-	synth_remove(&synth_decext);
-}
+module_spk_synth(synth_decext);
 
-module_init(decext_init);
-module_exit(decext_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
drivers/staging/speakup/speakup_decpc.c +1 -11
index 7c9c432..f7b9c8a 100644
@@ -491,18 +491,8 @@ module_param_named(start, synth_dec_pc.startup, short, S_IRUGO);
 
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
-static int __init decpc_init(void)
-{
-	return synth_add(&synth_dec_pc);
-}
-
-static void __exit decpc_exit(void)
-{
-	synth_remove(&synth_dec_pc);
-}
+module_spk_synth(synth_dec_pc);
 
-module_init(decpc_init);
-module_exit(decpc_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for DECtalk PC synthesizers");
drivers/staging/speakup/speakup_dectlk.c +1 -11
index 69e7c2b..b5a23d4 100644
@@ -306,18 +306,8 @@ module_param_named(start, synth_dectlk.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 dectlk_init(void)
-{
-	return synth_add(&synth_dectlk);
-}
-
-static void __exit dectlk_exit(void)
-{
-	synth_remove(&synth_dectlk);
-}
+module_spk_synth(synth_dectlk);
 
-module_init(dectlk_init);
-module_exit(dectlk_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for DECtalk Express synthesizers");
drivers/staging/speakup/speakup_dtlk.c +1 -11
index 89592c0..345efd3 100644
@@ -388,18 +388,8 @@ module_param_named(start, synth_dtlk.startup, short, S_IRUGO);
 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
-static int __init dtlk_init(void)
-{
-	return synth_add(&synth_dtlk);
-}
-
-static void __exit dtlk_exit(void)
-{
-	synth_remove(&synth_dtlk);
-}
+module_spk_synth(synth_dtlk);
 
-module_init(dtlk_init);
-module_exit(dtlk_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for DoubleTalk PC synthesizers");
drivers/staging/speakup/speakup_dummy.c +1 -11
index 362342a..f668112 100644
@@ -129,18 +129,8 @@ module_param_named(start, synth_dummy.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 dummy_init(void)
-{
-	return synth_add(&synth_dummy);
-}
+module_spk_synth(synth_dummy);
 
-static void __exit dummy_exit(void)
-{
-	synth_remove(&synth_dummy);
-}
-
-module_init(dummy_init);
-module_exit(dummy_exit);
 MODULE_AUTHOR("Samuel Thibault <[email protected]>");
 MODULE_DESCRIPTION("Speakup support for text console");
 MODULE_LICENSE("GPL");
drivers/staging/speakup/speakup_keypc.c +1 -11
index cef20fd..6ea0273 100644
@@ -319,18 +319,8 @@ module_param_named(start, synth_keypc.startup, short, S_IRUGO);
 MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
-static int __init keypc_init(void)
-{
-	return synth_add(&synth_keypc);
-}
-
-static void __exit keypc_exit(void)
-{
-	synth_remove(&synth_keypc);
-}
+module_spk_synth(synth_keypc);
 
-module_init(keypc_init);
-module_exit(keypc_exit);
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Keynote Gold PC synthesizers");
 MODULE_LICENSE("GPL");
drivers/staging/speakup/speakup_ltlk.c +1 -11
index 377a6e2..cc4806b 100644
@@ -175,18 +175,8 @@ module_param_named(start, synth_ltlk.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 ltlk_init(void)
-{
-	return synth_add(&synth_ltlk);
-}
-
-static void __exit ltlk_exit(void)
-{
-	synth_remove(&synth_ltlk);
-}
+module_spk_synth(synth_ltlk);
 
-module_init(ltlk_init);
-module_exit(ltlk_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for DoubleTalk LT/LiteTalk synthesizers");
drivers/staging/speakup/speakup_soft.c +1 -12
index e6e93fb..fb31bb9 100644
@@ -350,19 +350,8 @@ module_param_named(start, synth_soft.startup, short, S_IRUGO);
 
 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
 
+module_spk_synth(synth_soft);
 
-static int __init soft_init(void)
-{
-	return synth_add(&synth_soft);
-}
-
-static void __exit soft_exit(void)
-{
-	synth_remove(&synth_soft);
-}
-
-module_init(soft_init);
-module_exit(soft_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_DESCRIPTION("Speakup userspace software synthesizer support");
 MODULE_LICENSE("GPL");
drivers/staging/speakup/speakup_spkout.c +1 -11
index bccddf8..1007a61 100644
@@ -146,18 +146,8 @@ module_param_named(start, synth_spkout.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 spkout_init(void)
-{
-	return synth_add(&synth_spkout);
-}
-
-static void __exit spkout_exit(void)
-{
-	synth_remove(&synth_spkout);
-}
+module_spk_synth(synth_spkout);
 
-module_init(spkout_init);
-module_exit(spkout_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Speak Out synthesizers");
drivers/staging/speakup/speakup_txprt.c +1 -11
index dbe84b1..6c21e71 100644
@@ -127,18 +127,8 @@ module_param_named(start, synth_txprt.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 txprt_init(void)
-{
-	return synth_add(&synth_txprt);
-}
+module_spk_synth(synth_txprt);
 
-static void __exit txprt_exit(void)
-{
-	synth_remove(&synth_txprt);
-}
-
-module_init(txprt_init);
-module_exit(txprt_exit);
 MODULE_AUTHOR("Kirk Reiser <[email protected]>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Transport synthesizers");
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [Outreachy kernel] [PATCH v4 1/2] Staging: speakup: Add helper macro for spk_synth boilerplate

In reply to Vaishali Thakkar
Quoted 25 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.

---
Changes since v1:
- Use module_driver macro in definition of helper macro
Changes since v2:
- Correct unnecessory line wrapping of module_driver
- Split patch in to 2 patches
Changes since v3:
- Put blank line after module_spk_synth

 drivers/staging/speakup/spk_types.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/staging/speakup/spk_types.h +0 -0
index 8c565c9..38e0a3c 100644

drivers/staging/speakup/spk_types.h line 19

Quoted 4 lines
drivers/staging/speakup/spk_types.h +1 -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 */

Ah, more complaints sorry...

You aren't including this for 'struct device' you are doing it for module_driver(). Just remove the /* */ entirely, you don't need to specify why you are including a .h file, that's not needed.

thanks,

greg k-h

#3 lore raw

Re: [Outreachy kernel] [PATCH v4 1/2] Staging: speakup: Add helper macro for spk_synth boilerplate

Quoted 21 lines · Greg KH
Quoted 20 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.

---
Changes since v1:
- Use module_driver macro in definition of helper macro
Changes since v2:
- Correct unnecessory line wrapping of module_driver
- Split patch in to 2 patches
Changes since v3:
- Put blank line after module_spk_synth

 drivers/staging/speakup/spk_types.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 11 lines

drivers/staging/speakup/spk_types.h line 19

Quoted 9 lines
drivers/staging/speakup/spk_types.h +1 -0
index 8c565c9..38e0a3c 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 */

Ah, more complaints sorry...

No problem

Quoted 3 lines

You aren't including this for 'struct device' you are doing it for module_driver(). Just remove the /* */ entirely, you don't need to specify why you are including a .h file, that's not needed.

Yes but I thought as it is indirectly related to struct _spk_synth, I should add it here. May be my misunderstanding.

Anyways, I will drop entire comment in next version.

Thank You.

Quoted 3 lines

thanks,

greg k-h

Signature · 1 line
Vaishali