diff mbox series

[net-next,2/5] net: dsa: loop: Support 4K VLANs

Message ID 20200803200354.45062-3-f.fainelli@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series net: dsa: loop: Preparatory changes for | expand

Commit Message

Florian Fainelli Aug. 3, 2020, 8:03 p.m. UTC
Allocate a 4K array of VLANs instead of limiting ourselves to just 5
which is arbitrary.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/dsa_loop.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Andrew Lunn Aug. 3, 2020, 8:27 p.m. UTC | #1
On Mon, Aug 03, 2020 at 01:03:51PM -0700, Florian Fainelli wrote:
> Allocate a 4K array of VLANs instead of limiting ourselves to just 5
> which is arbitrary.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/net/dsa/dsa_loop.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
> index 4a57238cdfd8..6e97b44c6f3f 100644
> --- a/drivers/net/dsa/dsa_loop.c
> +++ b/drivers/net/dsa/dsa_loop.c
> @@ -48,12 +48,10 @@ struct dsa_loop_port {
>  	u16 pvid;
>  };
>  
> -#define DSA_LOOP_VLANS	5
> -
>  struct dsa_loop_priv {
>  	struct mii_bus	*bus;
>  	unsigned int	port_base;
> -	struct dsa_loop_vlan vlans[DSA_LOOP_VLANS];
> +	struct dsa_loop_vlan vlans[VLAN_N_VID];
>  	struct net_device *netdev;
>  	struct dsa_loop_port ports[DSA_MAX_PORTS];

That is 4K x (2 x u16) = 16K RAM. I suppose for a test driver which is
never expected to be used in production, that is O.K.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Florian Fainelli Aug. 3, 2020, 8:29 p.m. UTC | #2
On 8/3/2020 1:27 PM, Andrew Lunn wrote:
> On Mon, Aug 03, 2020 at 01:03:51PM -0700, Florian Fainelli wrote:
>> Allocate a 4K array of VLANs instead of limiting ourselves to just 5
>> which is arbitrary.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>>  drivers/net/dsa/dsa_loop.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
>> index 4a57238cdfd8..6e97b44c6f3f 100644
>> --- a/drivers/net/dsa/dsa_loop.c
>> +++ b/drivers/net/dsa/dsa_loop.c
>> @@ -48,12 +48,10 @@ struct dsa_loop_port {
>>  	u16 pvid;
>>  };
>>  
>> -#define DSA_LOOP_VLANS	5
>> -
>>  struct dsa_loop_priv {
>>  	struct mii_bus	*bus;
>>  	unsigned int	port_base;
>> -	struct dsa_loop_vlan vlans[DSA_LOOP_VLANS];
>> +	struct dsa_loop_vlan vlans[VLAN_N_VID];
>>  	struct net_device *netdev;
>>  	struct dsa_loop_port ports[DSA_MAX_PORTS];
> 
> That is 4K x (2 x u16) = 16K RAM. I suppose for a test driver which is
> never expected to be used in production, that is O.K.

I think so too, if we are worried we could switch to vmalloc() down the
road.

> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 
>     Andrew
>
diff mbox series

Patch

diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index 4a57238cdfd8..6e97b44c6f3f 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -48,12 +48,10 @@  struct dsa_loop_port {
 	u16 pvid;
 };
 
-#define DSA_LOOP_VLANS	5
-
 struct dsa_loop_priv {
 	struct mii_bus	*bus;
 	unsigned int	port_base;
-	struct dsa_loop_vlan vlans[DSA_LOOP_VLANS];
+	struct dsa_loop_vlan vlans[VLAN_N_VID];
 	struct net_device *netdev;
 	struct dsa_loop_port ports[DSA_MAX_PORTS];
 };
@@ -191,7 +189,7 @@  dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
 	/* Just do a sleeping operation to make lockdep checks effective */
 	mdiobus_read(bus, ps->port_base + port, MII_BMSR);
 
-	if (vlan->vid_end > DSA_LOOP_VLANS)
+	if (vlan->vid_end > ARRAY_SIZE(ps->vlans))
 		return -ERANGE;
 
 	return 0;