diff mbox series

[net-next,06/15] dsa: Remove const from tag driver ops structure

Message ID 20190418023120.17067-7-andrew@lunn.ch
State Changes Requested
Delegated to: David Miller
Headers show
Series Make DSA tag drivers kernel modules | expand

Commit Message

Andrew Lunn April 18, 2019, 2:31 a.m. UTC
A later patch will create a linked list of tag driver ops structures,
using a list_head in the structure. So the structure cannot be const.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c         |  2 +-
 net/dsa/dsa_priv.h    | 22 +++++++++++-----------
 net/dsa/tag_brcm.c    |  4 ++--
 net/dsa/tag_dsa.c     |  2 +-
 net/dsa/tag_edsa.c    |  2 +-
 net/dsa/tag_gswip.c   |  2 +-
 net/dsa/tag_ksz.c     |  4 ++--
 net/dsa/tag_lan9303.c |  2 +-
 net/dsa/tag_mtk.c     |  2 +-
 net/dsa/tag_qca.c     |  2 +-
 net/dsa/tag_trailer.c |  2 +-
 11 files changed, 23 insertions(+), 23 deletions(-)

Comments

Florian Fainelli April 18, 2019, 5:58 p.m. UTC | #1
On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> A later patch will create a linked list of tag driver ops structures,
> using a list_head in the structure. So the structure cannot be const.

Can't we encapsulate the existing dsa_device_ops, while leaving them
const into another structure which is not const? Similar to how we did
with the dsa_switch_driver structure?
Andrew Lunn April 18, 2019, 9:47 p.m. UTC | #2
On Thu, Apr 18, 2019 at 10:58:46AM -0700, Florian Fainelli wrote:
> 
> 
> On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> > A later patch will create a linked list of tag driver ops structures,
> > using a list_head in the structure. So the structure cannot be const.
> 
> Can't we encapsulate the existing dsa_device_ops, while leaving them
> const into another structure which is not const? Similar to how we did
> with the dsa_switch_driver structure?

Hi Florian

I was trying to keep it KISS, no dynamic memory allocation.

But i can make it more complex. For a tag driver with a single set of
ops, i can probably hide it all in the boiler plate, and make it all
static memory. For tag_brcm.c and tag_ksz.c, which have two ops
structures, i'm not sure i can hide it all.

I will think about it.

	Andrew
Florian Fainelli April 19, 2019, 3:26 p.m. UTC | #3
On 4/18/2019 2:47 PM, Andrew Lunn wrote:
> On Thu, Apr 18, 2019 at 10:58:46AM -0700, Florian Fainelli wrote:
>>
>>
>> On 4/17/2019 7:31 PM, Andrew Lunn wrote:
>>> A later patch will create a linked list of tag driver ops structures,
>>> using a list_head in the structure. So the structure cannot be const.
>>
>> Can't we encapsulate the existing dsa_device_ops, while leaving them
>> const into another structure which is not const? Similar to how we did
>> with the dsa_switch_driver structure?
> 
> Hi Florian
> 
> I was trying to keep it KISS, no dynamic memory allocation.
> 
> But i can make it more complex. For a tag driver with a single set of
> ops, i can probably hide it all in the boiler plate, and make it all
> static memory. For tag_brcm.c and tag_ksz.c, which have two ops
> structures, i'm not sure i can hide it all.

I don't think you need dynamic allocation, since you already have a
dsa_device_ops structure within each of the tagger source file, you can
just encapsulate that within the context of the file:

struct dsa_tag_driver {
	const char *name;
	const struct dsa_device_ops *ops;
}

Or something along those lines?
diff mbox series

Patch

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 2da733dff86b..5c37508747a0 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -34,7 +34,7 @@  static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 	return skb;
 }
 
-static const struct dsa_device_ops none_ops = {
+static struct dsa_device_ops none_ops = {
 	.name	= "none",
 	.proto	= DSA_TAG_PROTO_NONE,
 	.xmit	= dsa_slave_notag_xmit,
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 093b7d145eb1..32a063cefe46 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -202,32 +202,32 @@  int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
 
 /* tag_brcm.c */
-extern const struct dsa_device_ops brcm_netdev_ops;
-extern const struct dsa_device_ops brcm_prepend_netdev_ops;
+extern struct dsa_device_ops brcm_netdev_ops;
+extern struct dsa_device_ops brcm_prepend_netdev_ops;
 
 /* tag_dsa.c */
-extern const struct dsa_device_ops dsa_netdev_ops;
+extern struct dsa_device_ops dsa_netdev_ops;
 
 /* tag_edsa.c */
-extern const struct dsa_device_ops edsa_netdev_ops;
+extern struct dsa_device_ops edsa_netdev_ops;
 
 /* tag_gswip.c */
-extern const struct dsa_device_ops gswip_netdev_ops;
+extern struct dsa_device_ops gswip_netdev_ops;
 
 /* tag_ksz.c */
-extern const struct dsa_device_ops ksz9477_netdev_ops;
-extern const struct dsa_device_ops ksz9893_netdev_ops;
+extern struct dsa_device_ops ksz9477_netdev_ops;
+extern struct dsa_device_ops ksz9893_netdev_ops;
 
 /* tag_lan9303.c */
-extern const struct dsa_device_ops lan9303_netdev_ops;
+extern struct dsa_device_ops lan9303_netdev_ops;
 
 /* tag_mtk.c */
-extern const struct dsa_device_ops mtk_netdev_ops;
+extern struct dsa_device_ops mtk_netdev_ops;
 
 /* tag_qca.c */
-extern const struct dsa_device_ops qca_netdev_ops;
+extern struct dsa_device_ops qca_netdev_ops;
 
 /* tag_trailer.c */
-extern const struct dsa_device_ops trailer_netdev_ops;
+extern struct dsa_device_ops trailer_netdev_ops;
 
 #endif
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 39b380485e5a..756bade54fee 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -167,7 +167,7 @@  static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 	return nskb;
 }
 
-const struct dsa_device_ops brcm_netdev_ops = {
+struct dsa_device_ops brcm_netdev_ops = {
 	.name	= "brcm",
 	.proto	= DSA_TAG_PROTO_BRCM,
 	.xmit	= brcm_tag_xmit,
@@ -194,7 +194,7 @@  static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
 }
 
-const struct dsa_device_ops brcm_prepend_netdev_ops = {
+struct dsa_device_ops brcm_prepend_netdev_ops = {
 	.name	= "brcm-prepend",
 	.proto	= DSA_TAG_PROTO_BRCM_PREPEND,
 	.xmit	= brcm_tag_xmit_prepend,
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index ec9b66c11219..5db7dd21c73a 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -150,7 +150,7 @@  static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops dsa_netdev_ops = {
+struct dsa_device_ops dsa_netdev_ops = {
 	.name	= "dsa",
 	.proto	= DSA_TAG_PROTO_DSA,
 	.xmit	= dsa_xmit,
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 866d4e684511..94c6eed1905f 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -169,7 +169,7 @@  static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops edsa_netdev_ops = {
+struct dsa_device_ops edsa_netdev_ops = {
 	.name	= "edsa",
 	.proto	= DSA_TAG_PROTO_EDSA,
 	.xmit	= edsa_xmit,
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index 192156373108..f2cb183e4a8a 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -103,7 +103,7 @@  static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 	return skb;
 }
 
-const struct dsa_device_ops gswip_netdev_ops = {
+struct dsa_device_ops gswip_netdev_ops = {
 	.name = "gwsip",
 	.proto	= DSA_TAG_PROTO_GSWIP,
 	.xmit = gswip_tag_xmit,
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 5f5c8f9a6141..9c5f7db632a7 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -133,7 +133,7 @@  static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
 	return ksz_common_rcv(skb, dev, port, len);
 }
 
-const struct dsa_device_ops ksz9477_netdev_ops = {
+struct dsa_device_ops ksz9477_netdev_ops = {
 	.name	= "ksz9477",
 	.proto	= DSA_TAG_PROTO_KSZ9477,
 	.xmit	= ksz9477_xmit,
@@ -170,7 +170,7 @@  static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 	return nskb;
 }
 
-const struct dsa_device_ops ksz9893_netdev_ops = {
+struct dsa_device_ops ksz9893_netdev_ops = {
 	.name	= "ksz9893",
 	.proto	= DSA_TAG_PROTO_KSZ9893,
 	.xmit	= ksz9893_xmit,
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index b6ef1e1a6673..edfa15583607 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -128,7 +128,7 @@  static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-const struct dsa_device_ops lan9303_netdev_ops = {
+struct dsa_device_ops lan9303_netdev_ops = {
 	.name = "lan9303",
 	.proto	= DSA_TAG_PROTO_LAN9303,
 	.xmit = lan9303_xmit,
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index ca02ab3dcd80..dc51d7d05370 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -98,7 +98,7 @@  static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops mtk_netdev_ops = {
+struct dsa_device_ops mtk_netdev_ops = {
 	.name		= "mtk",
 	.proto		= DSA_TAG_PROTO_MTK,
 	.xmit		= mtk_tag_xmit,
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 1ff65c2e0cb4..e34c507e9e7e 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -99,7 +99,7 @@  static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops qca_netdev_ops = {
+struct dsa_device_ops qca_netdev_ops = {
 	.name	= "qca",
 	.proto	= DSA_TAG_PROTO_QCA,
 	.xmit	= qca_tag_xmit,
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 628ab1a44ed7..81a45c523ab7 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -77,7 +77,7 @@  static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-const struct dsa_device_ops trailer_netdev_ops = {
+struct dsa_device_ops trailer_netdev_ops = {
 	.name	= "trailer",
 	.proto	= DSA_TAG_PROTO_TRAILER,
 	.xmit	= trailer_xmit,