netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] net: dsa: introduce module_switch_driver macro
@ 2015-05-01 22:09 Vivien Didelot
  2015-05-01 22:09 ` [PATCH 2/3] net: dsa: sf2: use module_switch_driver Vivien Didelot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vivien Didelot @ 2015-05-01 22:09 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Vivien Didelot, David S. Miller, Florian Fainelli,
	Guenter Roeck, Andrew Lunn, kernel

This commit introduces a new module_switch_driver macro, similar to
module_platform_driver and such, to reduce boilerplate when declaring
DSA switch drivers.

In order to use the module_driver macro, register_switch_driver needed
to be changed to return an int instead of void, so make it return 0.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 include/net/dsa.h | 13 ++++++++++++-
 net/dsa/dsa.c     |  4 +++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index fbca63b..927f16a 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -11,6 +11,7 @@
 #ifndef __LINUX_NET_DSA_H
 #define __LINUX_NET_DSA_H
 
+#include <linux/device.h>
 #include <linux/if_ether.h>
 #include <linux/list.h>
 #include <linux/timer.h>
@@ -304,8 +305,18 @@ struct dsa_switch_driver {
 			       unsigned char *addr, bool *is_static);
 };
 
-void register_switch_driver(struct dsa_switch_driver *type);
+int register_switch_driver(struct dsa_switch_driver *type);
 void unregister_switch_driver(struct dsa_switch_driver *type);
+
+/* module_switch_driver() - Helper macro for 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_switch_driver(__switch_driver) \
+	module_driver(__switch_driver, register_switch_driver, \
+			unregister_switch_driver)
+
 struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
 
 static inline void *ds_to_priv(struct dsa_switch *ds)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index e6f6cc3..9630522 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -31,11 +31,13 @@ char dsa_driver_version[] = "0.1";
 static DEFINE_MUTEX(dsa_switch_drivers_mutex);
 static LIST_HEAD(dsa_switch_drivers);
 
-void register_switch_driver(struct dsa_switch_driver *drv)
+int register_switch_driver(struct dsa_switch_driver *drv)
 {
 	mutex_lock(&dsa_switch_drivers_mutex);
 	list_add_tail(&drv->list, &dsa_switch_drivers);
 	mutex_unlock(&dsa_switch_drivers_mutex);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(register_switch_driver);
 
-- 
2.3.7

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

* [PATCH 2/3] net: dsa: sf2: use module_switch_driver
  2015-05-01 22:09 [PATCH 1/3] net: dsa: introduce module_switch_driver macro Vivien Didelot
@ 2015-05-01 22:09 ` Vivien Didelot
  2015-05-01 22:09 ` [PATCH 3/3] net: dsa: mv88e6060: " Vivien Didelot
  2015-05-01 23:34 ` [PATCH 1/3] net: dsa: introduce module_switch_driver macro Florian Fainelli
  2 siblings, 0 replies; 6+ messages in thread
From: Vivien Didelot @ 2015-05-01 22:09 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Vivien Didelot, David S. Miller, Florian Fainelli,
	Guenter Roeck, Andrew Lunn, kernel

Use the module_switch_driver helper macro to declare the driver and thus
reduce boilerplate.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 drivers/net/dsa/bcm_sf2.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index cedb572..2b438fb 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1071,19 +1071,7 @@ static struct dsa_switch_driver bcm_sf2_switch_driver = {
 	.port_stp_update	= bcm_sf2_sw_br_set_stp_state,
 };
 
-static int __init bcm_sf2_init(void)
-{
-	register_switch_driver(&bcm_sf2_switch_driver);
-
-	return 0;
-}
-module_init(bcm_sf2_init);
-
-static void __exit bcm_sf2_exit(void)
-{
-	unregister_switch_driver(&bcm_sf2_switch_driver);
-}
-module_exit(bcm_sf2_exit);
+module_switch_driver(bcm_sf2_switch_driver);
 
 MODULE_AUTHOR("Broadcom Corporation");
 MODULE_DESCRIPTION("Driver for Broadcom Starfighter 2 ethernet switch chip");
-- 
2.3.7

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

* [PATCH 3/3] net: dsa: mv88e6060: use module_switch_driver
  2015-05-01 22:09 [PATCH 1/3] net: dsa: introduce module_switch_driver macro Vivien Didelot
  2015-05-01 22:09 ` [PATCH 2/3] net: dsa: sf2: use module_switch_driver Vivien Didelot
@ 2015-05-01 22:09 ` Vivien Didelot
  2015-05-01 23:34 ` [PATCH 1/3] net: dsa: introduce module_switch_driver macro Florian Fainelli
  2 siblings, 0 replies; 6+ messages in thread
From: Vivien Didelot @ 2015-05-01 22:09 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Vivien Didelot, David S. Miller, Florian Fainelli,
	Guenter Roeck, Andrew Lunn, kernel

Use the module_switch_driver helper macro to declare the driver and thus
reduce boilerplate.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 drivers/net/dsa/mv88e6060.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
index c29aebe..c58d5c9 100644
--- a/drivers/net/dsa/mv88e6060.c
+++ b/drivers/net/dsa/mv88e6060.c
@@ -283,18 +283,7 @@ static struct dsa_switch_driver mv88e6060_switch_driver = {
 	.poll_link	= mv88e6060_poll_link,
 };
 
-static int __init mv88e6060_init(void)
-{
-	register_switch_driver(&mv88e6060_switch_driver);
-	return 0;
-}
-module_init(mv88e6060_init);
-
-static void __exit mv88e6060_cleanup(void)
-{
-	unregister_switch_driver(&mv88e6060_switch_driver);
-}
-module_exit(mv88e6060_cleanup);
+module_switch_driver(mv88e6060_switch_driver);
 
 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
 MODULE_DESCRIPTION("Driver for Marvell 88E6060 ethernet switch chip");
-- 
2.3.7

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

* Re: [PATCH 1/3] net: dsa: introduce module_switch_driver macro
  2015-05-01 22:09 [PATCH 1/3] net: dsa: introduce module_switch_driver macro Vivien Didelot
  2015-05-01 22:09 ` [PATCH 2/3] net: dsa: sf2: use module_switch_driver Vivien Didelot
  2015-05-01 22:09 ` [PATCH 3/3] net: dsa: mv88e6060: " Vivien Didelot
@ 2015-05-01 23:34 ` Florian Fainelli
  2015-05-02 18:47   ` Vivien Didelot
  2 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2015-05-01 23:34 UTC (permalink / raw)
  To: Vivien Didelot, netdev
  Cc: linux-kernel, David S. Miller, Guenter Roeck, Andrew Lunn, kernel

On 01/05/15 15:09, Vivien Didelot wrote:
> This commit introduces a new module_switch_driver macro, similar to
> module_platform_driver and such, to reduce boilerplate when declaring
> DSA switch drivers.
> 
> In order to use the module_driver macro, register_switch_driver needed
> to be changed to return an int instead of void, so make it return 0.

Do we get much benefit from having this change, the diffstat looks
pretty neutral, ultimately register_switch_driver() might be gone (see:
http://www.spinics.net/lists/netdev/msg326900.html) and mv88e6xxx cannot
be converted to it due to how it is designed. This is not a strong
objection though, the changes look fine to me.

> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
> ---
>  include/net/dsa.h | 13 ++++++++++++-
>  net/dsa/dsa.c     |  4 +++-
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index fbca63b..927f16a 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -11,6 +11,7 @@
>  #ifndef __LINUX_NET_DSA_H
>  #define __LINUX_NET_DSA_H
>  
> +#include <linux/device.h>
>  #include <linux/if_ether.h>
>  #include <linux/list.h>
>  #include <linux/timer.h>
> @@ -304,8 +305,18 @@ struct dsa_switch_driver {
>  			       unsigned char *addr, bool *is_static);
>  };
>  
> -void register_switch_driver(struct dsa_switch_driver *type);
> +int register_switch_driver(struct dsa_switch_driver *type);
>  void unregister_switch_driver(struct dsa_switch_driver *type);
> +
> +/* module_switch_driver() - Helper macro for 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_switch_driver(__switch_driver) \
> +	module_driver(__switch_driver, register_switch_driver, \
> +			unregister_switch_driver)
> +
>  struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
>  
>  static inline void *ds_to_priv(struct dsa_switch *ds)
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index e6f6cc3..9630522 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -31,11 +31,13 @@ char dsa_driver_version[] = "0.1";
>  static DEFINE_MUTEX(dsa_switch_drivers_mutex);
>  static LIST_HEAD(dsa_switch_drivers);
>  
> -void register_switch_driver(struct dsa_switch_driver *drv)
> +int register_switch_driver(struct dsa_switch_driver *drv)
>  {
>  	mutex_lock(&dsa_switch_drivers_mutex);
>  	list_add_tail(&drv->list, &dsa_switch_drivers);
>  	mutex_unlock(&dsa_switch_drivers_mutex);
> +
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(register_switch_driver);
>  
> 


-- 
Florian

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

* Re: [PATCH 1/3] net: dsa: introduce module_switch_driver macro
  2015-05-01 23:34 ` [PATCH 1/3] net: dsa: introduce module_switch_driver macro Florian Fainelli
@ 2015-05-02 18:47   ` Vivien Didelot
  2015-05-02 19:00     ` Vivien Didelot
  0 siblings, 1 reply; 6+ messages in thread
From: Vivien Didelot @ 2015-05-02 18:47 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, linux-kernel, David, Guenter Roeck, Andrew Lunn, kernel

Hi Florian,

>> This commit introduces a new module_switch_driver macro, similar to
>> module_platform_driver and such, to reduce boilerplate when declaring
>> DSA switch drivers.
>>
>> In order to use the module_driver macro, register_switch_driver needed
>> to be changed to return an int instead of void, so make it return 0.
>
> Do we get much benefit from having this change, the diffstat looks
> pretty neutral, ultimately register_switch_driver() might be gone (see:
> http://www.spinics.net/lists/netdev/msg326900.html) and mv88e6xxx cannot
> be converted to it due to how it is designed. This is not a strong
> objection though, the changes look fine to me.

Indeed, I initially introduce the macro for that purpose, I have an RFC ready
to remove the mv88e6xxx module and expose its functions, since it'd better be a
library instead of a driver.

I'll attach it here as a reply to give an idea of what it looks like and 
get feedback from you.

Thanks,
-v

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

* Re: [PATCH 1/3] net: dsa: introduce module_switch_driver macro
  2015-05-02 18:47   ` Vivien Didelot
@ 2015-05-02 19:00     ` Vivien Didelot
  0 siblings, 0 replies; 6+ messages in thread
From: Vivien Didelot @ 2015-05-02 19:00 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, linux-kernel, David, Guenter Roeck, Andrew Lunn, kernel

Hi all,

>>> This commit introduces a new module_switch_driver macro, similar to
>>> module_platform_driver and such, to reduce boilerplate when declaring
>>> DSA switch drivers.
>>>
>>> In order to use the module_driver macro, register_switch_driver needed
>>> to be changed to return an int instead of void, so make it return 0.
>>
>> Do we get much benefit from having this change, the diffstat looks
>> pretty neutral, ultimately register_switch_driver() might be gone (see:
>> http://www.spinics.net/lists/netdev/msg326900.html) and mv88e6xxx cannot
>> be converted to it due to how it is designed. This is not a strong
>> objection though, the changes look fine to me.
> 
> Indeed, I initially introduce the macro for that purpose, I have an RFC ready
> to remove the mv88e6xxx module and expose its functions, since it'd better be a
> library instead of a driver.
> 
> I'll attach it here as a reply to give an idea of what it looks like and
> get feedback from you.

I messed up with the reply, here's the RFC: https://lkml.org/lkml/2015/5/2/150

Thanks,
-v

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

end of thread, other threads:[~2015-05-02 19:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-01 22:09 [PATCH 1/3] net: dsa: introduce module_switch_driver macro Vivien Didelot
2015-05-01 22:09 ` [PATCH 2/3] net: dsa: sf2: use module_switch_driver Vivien Didelot
2015-05-01 22:09 ` [PATCH 3/3] net: dsa: mv88e6060: " Vivien Didelot
2015-05-01 23:34 ` [PATCH 1/3] net: dsa: introduce module_switch_driver macro Florian Fainelli
2015-05-02 18:47   ` Vivien Didelot
2015-05-02 19:00     ` Vivien Didelot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).