Commit c269a24
committed
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>1 parent 2b446e6 commit c269a24
3 files changed
+18
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
288 | | - | |
289 | | - | |
| 287 | + | |
290 | 288 | | |
291 | 289 | | |
292 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10631 | 10631 | | |
10632 | 10632 | | |
10633 | 10633 | | |
| 10634 | + | |
| 10635 | + | |
| 10636 | + | |
| 10637 | + | |
| 10638 | + | |
| 10639 | + | |
| 10640 | + | |
| 10641 | + | |
| 10642 | + | |
| 10643 | + | |
| 10644 | + | |
10634 | 10645 | | |
10635 | 10646 | | |
10636 | 10647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3439 | 3439 | | |
3440 | 3440 | | |
3441 | 3441 | | |
3442 | | - | |
| 3442 | + | |
3443 | 3443 | | |
3444 | | - | |
3445 | | - | |
3446 | | - | |
3447 | | - | |
3448 | | - | |
3449 | | - | |
3450 | | - | |
3451 | | - | |
3452 | | - | |
3453 | | - | |
3454 | | - | |
3455 | | - | |
| 3444 | + | |
3456 | 3445 | | |
3457 | | - | |
3458 | | - | |
3459 | | - | |
3460 | | - | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
3461 | 3449 | | |
| 3450 | + | |
3462 | 3451 | | |
3463 | 3452 | | |
3464 | 3453 | | |
| |||
0 commit comments