net: dsa: rtl8366: Check VLAN ID and not ports

Message ID 20191001142843.10746-1-linus.walleij@linaro.org
State New
Headers show
Series
  • net: dsa: rtl8366: Check VLAN ID and not ports
Related show

Commit Message

Linus Walleij Oct. 1, 2019, 2:28 p.m.
There has been some confusion between the port number and
the VLAN ID in this driver. What we need to check for
validity is the VLAN ID, nothing else.

The current confusion came from assigning a few default
VLANs for default routing and we need to rewrite that
properly.

Instead of checking if the port number is a valid VLAN
ID, check the actual VLAN IDs passed in to the callback
one by one as expected.

Fixes: d8652956cf37 ("net: dsa: realtek-smi: Add Realtek SMI driver")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
ChangeLog v1->v2:
- Fix the iterator to actually check the VLAN ID.
- Use "vid" as variable name.
---
 drivers/net/dsa/rtl8366.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

-- 
2.21.0

Comments

David Miller Oct. 2, 2019, 4:10 p.m. | #1
From: Linus Walleij <linus.walleij@linaro.org>

Date: Tue,  1 Oct 2019 16:28:43 +0200

> There has been some confusion between the port number and

> the VLAN ID in this driver. What we need to check for

> validity is the VLAN ID, nothing else.

> 

> The current confusion came from assigning a few default

> VLANs for default routing and we need to rewrite that

> properly.

> 

> Instead of checking if the port number is a valid VLAN

> ID, check the actual VLAN IDs passed in to the callback

> one by one as expected.

> 

> Fixes: d8652956cf37 ("net: dsa: realtek-smi: Add Realtek SMI driver")

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


Applied and queued up for -stable, thanks.

Patch

diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c
index ca3d17e43ed8..ac88caca5ad4 100644
--- a/drivers/net/dsa/rtl8366.c
+++ b/drivers/net/dsa/rtl8366.c
@@ -339,10 +339,12 @@  int rtl8366_vlan_prepare(struct dsa_switch *ds, int port,
 			 const struct switchdev_obj_port_vlan *vlan)
 {
 	struct realtek_smi *smi = ds->priv;
+	u16 vid;
 	int ret;
 
-	if (!smi->ops->is_vlan_valid(smi, port))
-		return -EINVAL;
+	for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++)
+		if (!smi->ops->is_vlan_valid(smi, vid))
+			return -EINVAL;
 
 	dev_info(smi->dev, "prepare VLANs %04x..%04x\n",
 		 vlan->vid_begin, vlan->vid_end);
@@ -370,8 +372,9 @@  void rtl8366_vlan_add(struct dsa_switch *ds, int port,
 	u16 vid;
 	int ret;
 
-	if (!smi->ops->is_vlan_valid(smi, port))
-		return;
+	for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++)
+		if (!smi->ops->is_vlan_valid(smi, vid))
+			return;
 
 	dev_info(smi->dev, "add VLAN on port %d, %s, %s\n",
 		 port,