From: Jakub Kicinski Date: Thu, 31 Dec 2020 03:40:27 +0000 (-0800) Subject: net: vlan: avoid leaks on register_vlan_dev() failures X-Git-Tag: v4.14.216~26 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1f8b4552e300762727318a1a8a78e4dc8ffe5138;p=users%2Fdwmw2%2Flinux.git net: vlan: avoid leaks on register_vlan_dev() failures [ Upstream commit 55b7ab1178cbf41f979ff83236d3321ad35ed2ad ] VLAN checks for NETREG_UNINITIALIZED to distinguish between registration failure and unregistration in progress. Since commit cb626bf566eb ("net-sysfs: Fix reference count leak") registration failure may, however, result in NETREG_UNREGISTERED as well as NETREG_UNINITIALIZED. This fix is similer to cebb69754f37 ("rtnetlink: Fix memory(net_device) leak when ->newlink fails") Fixes: cb626bf566eb ("net-sysfs: Fix reference count leak") Signed-off-by: Jakub Kicinski Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index cf82d970b0e48..0efdf83f78e7a 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -272,7 +272,8 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id) return 0; out_free_newdev: - if (new_dev->reg_state == NETREG_UNINITIALIZED) + if (new_dev->reg_state == NETREG_UNINITIALIZED || + new_dev->reg_state == NETREG_UNREGISTERED) free_netdev(new_dev); return err; }