[PATCH net v2 0/2] net: dsa: tag_8021q: undo failed VLAN adds and a failed register
From: Julius Bairaktaris
Date: Sun Dec 06 2026 - 03:31:58 EST
dsa_tag_8021q_register() leaves ds->tag_8021q_ctx pointing at a freed
context when setting up a port fails, and keeps the VLANs of the ports
set up before that one. Patch 2 fixes this; it was v1.
Sashiko's review and Willem de Bruijn's review of v1 found that the
failing port is not cleaned up either: dsa_switch_tag_8021q_vlan_add()
returns on the first error without undoing the ports of the switch it
already programmed. That is a bug of its own, also hit when a bridge
join fails, so patch 1 fixes it in the notifier handler for every
caller, and patch 2 relies on it.
The register bug was found by an LLM review (Claude). Both were
reproduced in QEMU (x86_64, KASAN) with dsa_loop given the tag_8021q ops
and test-only error injection, one run per case on net 6902a2bb708:
- setup of port 2 fails: without the series an oops in
dsa_switch_tag_8021q_vlan_del(), with v1 or v2 clean;
- register fails at the CPU-port add for user port 1: without the
series the same oops, with v1 VLAN 3073 stays on port 1, with v2
every added VLAN is deleted;
- a bridge join fails at the CPU-port add of the bridge VLAN: without
the series and with v1 VLAN 3088 stays on port 0, with v2 it is
deleted.
Changes in v2:
- New patch 1: undo the partial add in dsa_switch_tag_8021q_vlan_add()
(Sashiko, Willem de Bruijn).
- Patch 2: err_free comment corrected, mt7628 named (Sashiko).
- v1: https://lore.kernel.org/netdev/20261128185520.852955-1-julius@xxxxxxxxxxxxxx/
I used Claude (Anthropic) to help write these patches.
Julius Bairaktaris (2):
net: dsa: tag_8021q: undo a partial VLAN add on the ports of a switch
net: dsa: tag_8021q: clear the context when dsa_tag_8021q_register()
fails
net/dsa/tag_8021q.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
base-commit: 6902a2bb708c4075d3de6ec18ab6a5864c4c1aa2
--
2.53.0