linux/drivers/net/usb
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
..
asix.h net: asix: Add in_pm parameter 2016-08-31 21:07:05 -07:00
asix_common.c net: asix: Avoid looping when the device does not respond 2016-10-14 16:06:54 -04:00
asix_devices.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
ax88172a.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
ax88179_178a.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
catc.c net: usb: catc: use new api ethtool_{get|set}_link_ksettings 2017-03-13 15:25:53 -07:00
cdc-phonet.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
cdc_eem.c
cdc_ether.c cdc-ether: divorce initialisation with a filter reset and a generic method 2017-05-23 11:01:28 -04:00
cdc_mbim.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
cdc_ncm.c net: cdc_ncm: Fix TX zero padding 2017-05-08 16:01:10 -04:00
cdc_subset.c
ch9200.c net: ch9200: add missing USB-descriptor endianness conversions 2017-05-12 12:15:46 -04:00
cx82310_eth.c cx82310_eth: use skb_cow_head() to deal with cloned skbs 2017-04-21 13:24:05 -04:00
dm9601.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
gl620a.c
hso.c net: hso: register netdev later to avoid a race condition 2017-04-28 16:11:48 -04:00
huawei_cdc_ncm.c cdc_ncm: Add support for moving NDP to end of NCM frame 2015-07-09 14:58:31 -07:00
int51x1.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
ipheth.c
kalmia.c scripts/spelling.txt: add "swith" pattern and fix typo instances 2017-02-27 18:43:46 -08:00
kaweth.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-21 20:23:53 -07:00
Kconfig usb: plusb: Add support for PL-27A1 2017-04-25 10:08:16 -04:00
lan78xx.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-21 20:23:53 -07:00
lan78xx.h lan78xx: add LAN7801 MAC only support 2016-12-08 14:21:47 -05:00
lg-vl600.c net: usb: Use eth_<foo>_addr instead of memset 2015-03-03 17:01:36 -05:00
Makefile USB: cdc_subset: only build when one driver is enabled 2016-02-18 15:59:45 -05:00
mcs7830.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
net1080.c
pegasus.c usbnet: pegasus: Use net_device_stats from struct net_device 2017-04-07 07:03:33 -07:00
pegasus.h usbnet: pegasus: Use net_device_stats from struct net_device 2017-04-07 07:03:33 -07:00
plusb.c usb: plusb: Add support for PL-27A1 2017-04-25 10:08:16 -04:00
qmi_wwan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
r8152.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-06 08:24:51 -07:00
rndis_host.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
rtl8150.c net: usb: rtl8150: use new api ethtool_{get|set}_link_ksettings 2017-03-13 15:25:54 -07:00
sierra_net.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
smsc75xx.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-21 20:23:53 -07:00
smsc75xx.h
smsc95xx.c smsc95xx: Support only IPv4 TCP/UDP csum offload 2017-05-21 13:31:48 -04:00
smsc95xx.h smsc95xx: Add comments to the registers definition 2017-04-17 13:04:52 -04:00
sr9700.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-21 20:23:53 -07:00
sr9700.h net: usb: sr9700: Use 'SR_' prefix for the common register macros 2015-02-04 13:53:02 -08:00
sr9800.c net: usbnet: support 64bit stats 2017-04-03 19:09:40 -07:00
sr9800.h
usbnet.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-15 21:16:30 -04:00
zaurus.c