linux/drivers/net/ethernet
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
..
3com Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
8390 net: ethernet: ax88796: don't call free_irq without request_irq first 2017-05-26 14:55:38 -04:00
adaptec
adi net: bfin_mac: Remove unused stats member from struct bfin_mac_local 2017-03-27 16:01:59 -07:00
aeroflex net: greth: Utilize of_get_mac_address() 2017-03-22 12:00:39 -07:00
agere
alacritech
allwinner
alteon
altera
amazon net/ena: switch to pci_alloc_irq_vectors 2017-04-11 11:16:03 -04:00
amd amd-xgbe: use PAGE_ALLOC_COSTLY_ORDER in xgbe_map_rx_buffer 2017-06-04 20:01:00 -04:00
apm drivers: net: xgene-v2: Fix error return code in xge_mdio_config() 2017-04-25 13:48:06 -04:00
apple
aquantia ethernet: aquantia: remove redundant checks on error status 2017-05-11 21:42:17 -04:00
arc net: arc_emac: switch to phy_start()/phy_stop() 2017-04-21 15:23:52 -04:00
atheros net: atheros: atl2: don't return zero on failure path in atl2_probe() 2017-05-22 12:05:01 -04:00
aurora
broadcom bnx2x: fix pf2vf bulletin DMA mapping leak 2017-06-07 12:59:42 -04:00
brocade bna: ethtool: Avoid reading past end of buffer 2017-05-08 14:41:42 -04:00
cadence net: macb: fix phy interrupt parsing 2017-04-30 22:21:49 -04:00
calxeda
cavium net: thunderx: Optimize page recycling for XDP 2017-05-02 15:41:22 -04:00
chelsio net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
cirrus Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
cisco
davicom
dec Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
dlink net: dl2k: Use net_device_stats from struct net_device 2017-04-07 07:03:33 -07:00
emulex be2net: Fix offload features for Q-in-Q packets 2017-05-24 16:27:14 -04:00
ezchip Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-06 08:24:51 -07:00
faraday net: ethernet: faraday: To support device tree usage. 2017-05-18 10:10:44 -04:00
freescale net: freescale: fix potential null pointer dereference 2017-05-31 14:23:38 -04:00
fujitsu
hisilicon format-security: move static strings to const 2017-05-08 17:15:14 -07:00
hp Annotate hardware config module parameters in drivers/net/ethernet/ 2017-04-20 12:02:32 +01:00
i825xx
ibm ibmvnic: Return failure on attempted mtu change 2017-06-07 15:02:45 -04:00
intel i40e/i40evf: proper update of the page_offset field 2017-06-06 02:49:15 -07:00
marvell net: mvpp2: do not bypass the mvpp22_port_mii_set function 2017-06-07 15:08:10 -04:00
mediatek Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-20 10:35:33 -04:00
mellanox net/mlx4: Check if Granular QoS per VF has been enabled before updating QP qos_vport 2017-06-05 11:29:54 -04:00
micrel
microchip
moxa net: moxa: Use net_device_stats from struct net_device 2017-04-07 07:03:33 -07:00
myricom
natsemi format-security: move static strings to const 2017-05-08 17:15:14 -07:00
neterion
netronome xdp: use common helper for netlink extended ack reporting 2017-05-03 09:51:24 -04:00
nuvoton net: nuvoton: Use net_device_stats from struct net_device 2017-04-07 07:03:33 -07:00
nvidia forcedeth: remove unnecessary carrier status check 2017-05-04 10:57:41 -04:00
nxp
oki-semi
packetengines
pasemi
qlogic qlcnic: Fix tunnel offload for 82xx adapters 2017-06-02 14:30:58 -04:00
qualcomm net: qcom/emac: do not use hardware mdio automatic polling 2017-06-04 19:32:09 -04:00
rdc
realtek Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
renesas ravb: Fix use-after-free on ifconfig eth0 down 2017-06-06 16:02:22 -04:00
rocker Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-06 08:24:51 -07:00
samsung scripts/spelling.txt: add "intialise(d)" pattern and fix typo instances 2017-05-08 17:15:13 -07:00
seeq
sfc sfc: revert changes to NIC revision numbers 2017-05-12 12:22:53 -04:00
sgi
silan
sis
smsc Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
stmicro net: stmmac: fix a broken u32 less than zero check 2017-06-06 16:26:28 -04:00
sun ldmvsw: stop the clean timer at beginning of remove 2017-05-15 15:36:08 -04:00
synopsys net: dwc-xlgmac: add the initial ethtool support 2017-04-13 13:46:38 -04:00
tehuti net: tehuti: use new api ethtool_{get|set}_link_ksettings 2017-03-27 16:00:07 -07:00
ti net: netcp: fix check of requested timestamping filter 2017-05-15 15:21:03 -04:00
tile
toshiba format-security: move static strings to const 2017-05-08 17:15:14 -07:00
tundra
via
wiznet net: ethernet: wiznet: avoid format string exposure 2017-04-06 13:38:11 -07:00
xilinx
xircom
xscale
dnet.c
dnet.h
ec_bhf.c
ethoc.c net: ethoc: enable NAPI before poll may be scheduled 2017-06-06 16:22:51 -04:00
fealnx.c
jme.c
jme.h
Kconfig
korina.c
lantiq_etop.c
Makefile
netx-eth.c