All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
@ 2015-03-16 14:29 Vaishali Thakkar
  2015-03-16 15:28 ` [Outreachy kernel] " Greg KH
  2015-03-16 16:49 ` Julia Lawall
  0 siblings, 2 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-03-16 14:29 UTC (permalink / raw)
  To: outreachy-kernel

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.

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
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(-)

diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c
index 5cbaec8..ea89e36 100644
--- a/drivers/staging/speakup/speakup_audptr.c
+++ b/drivers/staging/speakup/speakup_audptr.c
@@ -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 <kirk@braille.uwo.ca>");
 MODULE_AUTHOR("David Borowski");
 MODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
diff --git a/drivers/staging/speakup/spk_types.h b/drivers/staging/speakup/spk_types.h
index 8c565c9..67aa5e9 100644
--- a/drivers/staging/speakup/spk_types.h
+++ b/drivers/staging/speakup/spk_types.h
@@ -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;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 14:29 [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate Vaishali Thakkar
@ 2015-03-16 15:28 ` Greg KH
  2015-03-16 15:30   ` Vaishali Thakkar
  2015-03-16 16:49 ` Julia Lawall
  1 sibling, 1 reply; 8+ messages in thread
From: Greg KH @ 2015-03-16 15:28 UTC (permalink / raw)
  To: Vaishali Thakkar; +Cc: outreachy-kernel

On Mon, Mar 16, 2015 at 07:59:01PM +0530, Vaishali Thakkar wrote:
> 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.
> 
> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> ---
> 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(-)

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 15:28 ` [Outreachy kernel] " Greg KH
@ 2015-03-16 15:30   ` Vaishali Thakkar
  0 siblings, 0 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-03-16 15:30 UTC (permalink / raw)
  To: Greg KH; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

On Mar 16, 2015 8:58 PM, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>
> On Mon, Mar 16, 2015 at 07:59:01PM +0530, Vaishali Thakkar wrote:
> > 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.
> >
> > Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> > ---
> > 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(-)
>
> 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

> thanks,
>
> greg k-h

[-- Attachment #2: Type: text/html, Size: 1766 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 14:29 [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate Vaishali Thakkar
  2015-03-16 15:28 ` [Outreachy kernel] " Greg KH
@ 2015-03-16 16:49 ` Julia Lawall
  2015-03-16 17:04   ` Vaishali Thakkar
  1 sibling, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2015-03-16 16:49 UTC (permalink / raw)
  To: Vaishali Thakkar; +Cc: outreachy-kernel

> +#define module_spk_synth(__spk_synth) \
> +	module_driver(__spk_synth, synth_add, \
> +			synth_remove)

Why the newline before synth_remove?

julia


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 16:49 ` Julia Lawall
@ 2015-03-16 17:04   ` Vaishali Thakkar
  2015-03-16 17:08     ` Greg KH
  2015-03-16 20:41     ` Julia Lawall
  0 siblings, 2 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-03-16 17:04 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel

On Mon, Mar 16, 2015 at 10:19 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> +#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) \

> julia



-- 
Vaishali


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 17:04   ` Vaishali Thakkar
@ 2015-03-16 17:08     ` Greg KH
  2015-03-16 17:10       ` Vaishali Thakkar
  2015-03-16 20:41     ` Julia Lawall
  1 sibling, 1 reply; 8+ messages in thread
From: Greg KH @ 2015-03-16 17:08 UTC (permalink / raw)
  To: Vaishali Thakkar; +Cc: Julia Lawall, outreachy-kernel

On Mon, Mar 16, 2015 at 10:34:34PM +0530, Vaishali Thakkar wrote:
> On Mon, Mar 16, 2015 at 10:19 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >> +#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) \

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

thanks,

greg k-h


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 17:08     ` Greg KH
@ 2015-03-16 17:10       ` Vaishali Thakkar
  0 siblings, 0 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-03-16 17:10 UTC (permalink / raw)
  To: Greg KH; +Cc: Julia Lawall, outreachy-kernel

On Mon, Mar 16, 2015 at 10:38 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Mon, Mar 16, 2015 at 10:34:34PM +0530, Vaishali Thakkar wrote:
>> On Mon, Mar 16, 2015 at 10:19 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> >> +#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) \
>
> 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.

> thanks,
>
> greg k-h



-- 
Vaishali


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate
  2015-03-16 17:04   ` Vaishali Thakkar
  2015-03-16 17:08     ` Greg KH
@ 2015-03-16 20:41     ` Julia Lawall
  1 sibling, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2015-03-16 20:41 UTC (permalink / raw)
  To: Vaishali Thakkar; +Cc: outreachy-kernel



On Mon, 16 Mar 2015, Vaishali Thakkar wrote:

> On Mon, Mar 16, 2015 at 10:19 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >> +#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) \

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

julia


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-16 20:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 14:29 [PATCH v2] Staging: speakup: Add helper macro for spk_synth boilerplate Vaishali Thakkar
2015-03-16 15:28 ` [Outreachy kernel] " Greg KH
2015-03-16 15:30   ` Vaishali Thakkar
2015-03-16 16:49 ` Julia Lawall
2015-03-16 17:04   ` Vaishali Thakkar
2015-03-16 17:08     ` Greg KH
2015-03-16 17:10       ` Vaishali Thakkar
2015-03-16 20:41     ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.