Re: [PATCH net-next v7 07/16] net: dsa: vsc73xx: Add vlan filtering

From: Simon Horman
Date: Tue Mar 26 2024 - 07:04:08 EST


On Mon, Mar 25, 2024 at 09:43:32PM +0100, Pawel Dembicki wrote:
> This patch implements VLAN filtering for the vsc73xx driver.
>
> After starting VLAN filtering, the switch is reconfigured from QinQ to
> a simple VLAN aware mode. This is required because VSC73XX chips do not
> support inner VLAN tag filtering.
>
> Signed-off-by: Pawel Dembicki <paweldembicki@xxxxxxxxx>

..

> +static int vsc73xx_port_vlan_add(struct dsa_switch *ds, int port,
> + const struct switchdev_obj_port_vlan *vlan,
> + struct netlink_ext_ack *extack)
> +{
> + bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
> + bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
> + struct dsa_port *dp = dsa_to_port(ds, port);
> + enum vsc73xx_port_vlan_conf port_vlan_conf;
> + struct vsc73xx_bridge_vlan *vsc73xx_vlan;
> + struct vsc73xx_vlan_summary summary;
> + struct vsc73xx *vsc = ds->priv;
> + bool operate_on_storage;
> + int ret;
> + u16 vid;
> +
> + /* Be sure to deny alterations to the configuration done by tag_8021q.
> + */
> + if (vid_is_dsa_8021q(vlan->vid)) {
> + NL_SET_ERR_MSG_MOD(extack,
> + "Range 3072-4095 reserved for dsa_8021q operation");
> + return -EBUSY;
> + }
> +
> + /* The processed vlan->vid is excluded from the search because the VLAN
> + * can be re-added with a different set of flags, so it's easiest to
> + * ignore its old flags from the VLAN database software copy.
> + */
> + vsc73xx_bridge_vlan_summary(vsc, port, &summary, vlan->vid);
> +
> + /* VSC73XX allow only three untagged states: none, one or all */
> + if ((untagged && summary.num_tagged > 0 && summary.num_untagged > 0) ||
> + (!untagged && summary.num_untagged > 1)) {
> + NL_SET_ERR_MSG_MOD(extack,
> + "Port can have only none, one or all untagged vlan");
> + return -EBUSY;
> + }
> +
> + vsc73xx_vlan = vsc73xx_bridge_vlan_find(vsc, vlan->vid);
> +
> + if (!vsc73xx_vlan) {
> + vsc73xx_vlan = kzalloc(sizeof(*vsc73xx_vlan), GFP_KERNEL);
> + if (!vsc73xx_vlan)
> + return -ENOMEM;
> +
> + vsc73xx_vlan->vid = vlan->vid;
> + vsc73xx_vlan->portmask = 0;
> + vsc73xx_vlan->untagged = 0;
> +
> + INIT_LIST_HEAD(&vsc73xx_vlan->list);
> + list_add_tail(&vsc73xx_vlan->list, &vsc->vlans);
> + }
> +
> + vsc73xx_vlan->portmask |= BIT(port);
> +
> + if (untagged)
> + vsc73xx_vlan->untagged |= BIT(port);
> + else
> + vsc73xx_vlan->untagged &= ~BIT(port);
> +
> + /* CPU port must be always tagged because port separation is based on
> + * tag_8021q.
> + */
> + if (port == CPU_PORT)
> + goto update_vlan_table;
> +
> + operate_on_storage = vsc73xx_tag_8021q_active(dp);
> +
> + if (pvid)
> + ret = vsc73xx_vlan_set_pvid(vsc, port, vlan->vid,
> + operate_on_storage, false);
> + else if (vsc73xx_port_get_pvid(vsc, port, &vid, false) &&
> + vid == vlan->vid)
> + ret = vsc73xx_vlan_clear_pvid(vsc, port, operate_on_storage,
> + false);

Hi Pawel,

some minor feedback from my side.

If neither of the above conditions immediately above is met,
then ret will be used ininitialised on the line below.

Flagged by clang-17 W=1 build, and Smatch.

> + if (ret)
> + goto err;

..

--
pw-bot: changes-requested