diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2022-12-10 01:52:42 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-12-31 13:32:29 +0100 |
commit | 14ed46a13aba42a6ddd85de6f6274090df3586a5 (patch) | |
tree | b446c3cd94b5758962bff3c6bb07c36e74e4ba00 | |
parent | 06b81b4e669a7c5cce4ca67d5938f98f030a6414 (diff) | |
download | linux-stable-14ed46a13aba42a6ddd85de6f6274090df3586a5.tar.gz linux-stable-14ed46a13aba42a6ddd85de6f6274090df3586a5.tar.bz2 linux-stable-14ed46a13aba42a6ddd85de6f6274090df3586a5.zip |
net: dsa: tag_8021q: avoid leaking ctx on dsa_tag_8021q_register() error path
[ Upstream commit e095493091e850d5292ad01d8fbf5cde1d89ac53 ]
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: 328621f6131f ("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>
-rw-r--r-- | net/dsa/tag_8021q.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 34e5ec5d3e23..89371b16416e 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -398,6 +398,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) @@ -410,7 +411,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); |