Skip to content

Commit 2e3514e

Browse files
MocLGkuba-moo
authored andcommitted
net: hsr: fix VLAN add unwind on slave errors
When vlan_vid_add() fails for a secondary slave, the error path calls vlan_vid_del() on the failing port instead of the peer slave that had already succeeded. This results in asymmetric VLAN state across the HSR pair. Fix this by switching to a centralized unwind path that removes the VID from any slave device that was already programmed. Fixes: 1a8a63a ("net: hsr: Add VLAN CTAG filter support") Signed-off-by: Luka Gejak <luka.gejak@linux.dev> Link: https://patch.msgid.link/20260401092243.52121-3-luka.gejak@linux.dev Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f5df299 commit 2e3514e

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

net/hsr/hsr_device.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ static void hsr_change_rx_flags(struct net_device *dev, int change)
532532
static int hsr_ndo_vlan_rx_add_vid(struct net_device *dev,
533533
__be16 proto, u16 vid)
534534
{
535-
bool is_slave_a_added = false;
536-
bool is_slave_b_added = false;
535+
struct net_device *slave_a_dev = NULL;
536+
struct net_device *slave_b_dev = NULL;
537537
struct hsr_port *port;
538538
struct hsr_priv *hsr;
539539
int ret = 0;
@@ -549,33 +549,35 @@ static int hsr_ndo_vlan_rx_add_vid(struct net_device *dev,
549549
switch (port->type) {
550550
case HSR_PT_SLAVE_A:
551551
if (ret) {
552-
/* clean up Slave-B */
553552
netdev_err(dev, "add vid failed for Slave-A\n");
554-
if (is_slave_b_added)
555-
vlan_vid_del(port->dev, proto, vid);
556-
return ret;
553+
goto unwind;
557554
}
558-
559-
is_slave_a_added = true;
555+
slave_a_dev = port->dev;
560556
break;
561-
562557
case HSR_PT_SLAVE_B:
563558
if (ret) {
564-
/* clean up Slave-A */
565559
netdev_err(dev, "add vid failed for Slave-B\n");
566-
if (is_slave_a_added)
567-
vlan_vid_del(port->dev, proto, vid);
568-
return ret;
560+
goto unwind;
569561
}
570-
571-
is_slave_b_added = true;
562+
slave_b_dev = port->dev;
572563
break;
573564
default:
565+
if (ret)
566+
goto unwind;
574567
break;
575568
}
576569
}
577570

578571
return 0;
572+
573+
unwind:
574+
if (slave_a_dev)
575+
vlan_vid_del(slave_a_dev, proto, vid);
576+
577+
if (slave_b_dev)
578+
vlan_vid_del(slave_b_dev, proto, vid);
579+
580+
return ret;
579581
}
580582

581583
static int hsr_ndo_vlan_rx_kill_vid(struct net_device *dev,

0 commit comments

Comments
 (0)