Skip to content

Commit

Permalink
net: dsa: tag_8021q: avoid leaking ctx on dsa_tag_8021q_register() er…
Browse files Browse the repository at this point in the history
…ror path

[ Upstream commit e095493 ]

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 <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20221209235242.480344-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
vladimiroltean authored and gregkh committed Dec 31, 2022
1 parent 86664b8 commit 09f30f3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion net/dsa/tag_8021q.c
Expand Up @@ -529,6 +529,7 @@ static void dsa_tag_8021q_teardown(struct dsa_switch *ds)
int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
{
struct dsa_8021q_context *ctx;
int err;

ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
Expand All @@ -541,7 +542,15 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)

ds->tag_8021q_ctx = ctx;

return dsa_tag_8021q_setup(ds);
err = dsa_tag_8021q_setup(ds);
if (err)
goto err_free;

return 0;

err_free:
kfree(ctx);
return err;
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_register);

Expand Down

0 comments on commit 09f30f3

Please sign in to comment.