Skip to content

Commit e095493

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: tag_8021q: avoid leaking ctx on dsa_tag_8021q_register() error path
If dsa_tag_8021q_setup() fails, for example due to the inability of the device to install a VLAN, the tag_8021q context of the switch will leak. Make sure it is freed on the error path. Fixes: 328621f ("net: dsa: tag_8021q: absorb dsa_8021q_setup into dsa_tag_8021q_{,un}register") Signed-off-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0c87b54 commit e095493

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

net/dsa/tag_8021q.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ static void dsa_tag_8021q_teardown(struct dsa_switch *ds)
398398
int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
399399
{
400400
struct dsa_8021q_context *ctx;
401+
int err;
401402

402403
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
403404
if (!ctx)
@@ -410,7 +411,15 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
410411

411412
ds->tag_8021q_ctx = ctx;
412413

413-
return dsa_tag_8021q_setup(ds);
414+
err = dsa_tag_8021q_setup(ds);
415+
if (err)
416+
goto err_free;
417+
418+
return 0;
419+
420+
err_free:
421+
kfree(ctx);
422+
return err;
414423
}
415424
EXPORT_SYMBOL_GPL(dsa_tag_8021q_register);
416425

0 commit comments

Comments
 (0)