diff options
author | Jakub Kicinski <kuba@kernel.org> | 2021-01-06 10:40:06 -0800 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2021-01-08 19:27:41 -0800 |
commit | c269a24ce057abfc31130960e96ab197ef6ab196 (patch) | |
tree | b79fe7cf795777ab5e5a46d3520929a6607dfea1 /net/8021q | |
parent | 2b446e650b418f9a9e75f99852e2f2560cabfa17 (diff) |
net: make free_netdev() more lenient with unregistering devices
There are two flavors of handling netdev registration:
- ones called without holding rtnl_lock: register_netdev() and
unregister_netdev(); and
- those called with rtnl_lock held: register_netdevice() and
unregister_netdevice().
While the semantics of the former are pretty clear, the same can't
be said about the latter. The netdev_todo mechanism is utilized to
perform some of the device unregistering tasks and it hooks into
rtnl_unlock() so the locked variants can't actually finish the work.
In general free_netdev() does not mix well with locked calls. Most
drivers operating under rtnl_lock set dev->needs_free_netdev to true
and expect core to make the free_netdev() call some time later.
The part where this becomes most problematic is error paths. There is
no way to unwind the state cleanly after a call to register_netdevice(),
since unreg can't be performed fully without dropping locks.
Make free_netdev() more lenient, and defer the freeing if device
is being unregistered. This allows error paths to simply call
free_netdev() both after register_netdevice() failed, and after
a call to unregister_netdevice() but before dropping rtnl_lock.
Simplify the error paths which are currently doing gymnastics
around free_netdev() handling.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/8021q')
-rw-r--r-- | net/8021q/vlan.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 15bbfaf943fd..8b644113715e 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -284,9 +284,7 @@ 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 || - new_dev->reg_state == NETREG_UNREGISTERED) - free_netdev(new_dev); + free_netdev(new_dev); return err; } |