linux/drivers/net/wan
David S. Miller cf124db566 net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init().  However, the release of these resources
can occur in one of two different places.

Either netdev_ops->ndo_uninit() or netdev->destructor().

The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.

netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.

netdev->destructor(), on the other hand, does not run until the
netdev references all go away.

Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().

This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.

If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit().  But
it is not able to invoke netdev->destructor().

This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.

However, this means that the resources that would normally be released
by netdev->destructor() will not be.

Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.

Many drivers do not try to deal with this, and instead we have leaks.

Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().

netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().

netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().

Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().

And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().

Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-07 15:53:24 -04:00
..
lmc Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
.gitignore
c101.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
cosa.c Annotate hardware config module parameters in drivers/net/wan/ 2017-04-20 12:02:32 +01:00
cosa.h
dlci.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
dscc4.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
farsync.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
farsync.h
fsl_ucc_hdlc.c ucc/hdlc: fix two little issue 2017-03-13 21:53:48 -07:00
fsl_ucc_hdlc.h drivers/net/fsl_ucc: Do not prefix header guard with CONFIG_ 2016-06-08 11:07:17 -07:00
hd64570.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
hd64570.h net: Spelling s/transmition/transmission/ 2014-01-14 17:11:26 -08:00
hd64572.c drivers: net: generalize napi_complete_done() 2017-01-30 15:10:42 -05:00
hd64572.h net: Spelling s/transmition/transmission/ 2014-01-14 17:11:26 -08:00
hdlc_cisco.c WAN: HDLC: Call notifiers before and after changing device type 2015-12-05 17:41:42 -05:00
hdlc_fr.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
hdlc_ppp.c WAN: HDLC: Call notifiers before and after changing device type 2015-12-05 17:41:42 -05:00
hdlc_raw_eth.c WAN: HDLC: Call notifiers before and after changing device type 2015-12-05 17:41:42 -05:00
hdlc_raw.c WAN: HDLC: Call notifiers before and after changing device type 2015-12-05 17:41:42 -05:00
hdlc_x25.c WAN: HDLC: Call notifiers before and after changing device type 2015-12-05 17:41:42 -05:00
hdlc.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
hostess_sv11.c Annotate hardware config module parameters in drivers/net/wan/ 2017-04-20 12:02:32 +01:00
ixp4xx_hss.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
Kconfig net: wan: slic_ds26522: Allow driver to built if COMPILE_TEST is enabled 2016-10-14 10:11:49 -04:00
lapbether.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
Makefile Maxim/driver: Add driver for maxim ds26522 2016-06-29 04:05:14 -04:00
n2.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
pc300too.c wan: pc300too: abort path on failure 2017-04-24 15:51:31 -04:00
pci200syn.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
sbni.c Annotate hardware config module parameters in drivers/net/wan/ 2017-04-20 12:02:32 +01:00
sbni.h
sdla.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
sealevel.c Annotate hardware config module parameters in drivers/net/wan/ 2017-04-20 12:02:32 +01:00
slic_ds26522.c net: wan: slic_ds26522: Remove .owner field for driver 2017-02-07 11:41:15 -05:00
slic_ds26522.h Maxim/driver: Add driver for maxim ds26522 2016-06-29 04:05:14 -04:00
wanxl.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
wanxl.h
wanxlfw.inc_shipped
wanxlfw.S
x25_asy.c net: use core MTU range checking in WAN drivers 2016-10-20 14:51:09 -04:00
x25_asy.h
z85230.c Doc: z8530book: Fix typo in API-z8530-sync-txdma-open.html 2015-07-10 23:45:31 -07:00
z85230.h