Re: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
From: Sverdlin, Alexander
Date: Thu Aug 21 2025 - 12:45:43 EST
Hi Daniel,
On Sat, 2025-08-16 at 20:53 +0100, Daniel Golle wrote:
> Dynamically allocate vlans array depending on the switch API version.
> Versions less than 2.2 support 64 VLANs, versions 2.2 or later support
> 4096 VLANs.
...
> @@ -725,9 +730,9 @@ static int gswip_vlan_active_create(struct gswip_priv *priv,
> return err;
> }
>
> - priv->vlans[idx].bridge = bridge;
> - priv->vlans[idx].vid = vid;
> - priv->vlans[idx].fid = fid;
> + (*priv->vlans)[idx].bridge = bridge;
> + (*priv->vlans)[idx].vid = vid;
> + (*priv->vlans)[idx].fid = fid;
Would it be possible to leave this chunk unchanged (and all array
dereferencing in the driver as well)?
> @@ -1948,6 +1953,22 @@ static int gswip_validate_cpu_port(struct dsa_switch *ds)
> return 0;
> }
>
> +static int gswip_allocate_vlans(struct gswip_priv *priv)
> +{
> + if (GSWIP_VERSION_GE(priv, GSWIP_VERSION_2_2))
> + priv->num_vlans = 4096;
> + else
> + priv->num_vlans = 64;
> +
> + priv->vlans = devm_kcalloc(priv->dev, priv->num_vlans,
> + sizeof((*priv->vlans)[0]), GFP_KERNEL);
maybe sizeof(*priv->vlans) or sizeof(priv->vlans[0])?
> --- a/drivers/net/dsa/lantiq_gswip.h
> +++ b/drivers/net/dsa/lantiq_gswip.h
> @@ -269,7 +270,8 @@ struct gswip_priv {
> struct dsa_switch *ds;
> struct device *dev;
> struct regmap *rcu_regmap;
> - struct gswip_vlan vlans[64];
> + struct gswip_vlan (*vlans)[];
... if this would be just "struct gswip_vlan *vlans;"?
> + unsigned int num_vlans;
> int num_gphy_fw;
> struct gswip_gphy_fw *gphy_fw;
> u32 port_vlan_filter;
--
Alexander Sverdlin
Siemens AG
www.siemens.com