linux_dsm_epyc7002/drivers/net/can
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
..
c_can drivers: net: generalize napi_complete_done() 2017-01-30 15:10:42 -05:00
cc770 Annotate hardware config module parameters in drivers/net/can/ 2017-04-20 12:02:32 +01:00
ifi_canfd can: ifi: use correct register to read rx status 2017-04-04 17:48:22 +02:00
m_can can: m_can: Enable TX FIFO Handling for M_CAN IP version >= v3.1.x 2017-04-25 09:00:48 +02:00
mscan treewide: replace dev->trans_start update with helper 2016-05-04 14:16:49 -04:00
peak_canfd can: peak: add support for PEAK PCAN-PCIe FD CAN-FD boards 2017-04-25 09:00:45 +02:00
rcar scripts/spelling.txt: add regsiter -> register spelling mistake 2017-05-08 17:15:13 -07:00
sja1000 Annotate hardware config module parameters in drivers/net/can/ 2017-04-20 12:02:32 +01:00
softing sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
spi can: hi311x: Add Holt HI-311x CAN driver 2017-04-04 17:35:59 +02:00
usb Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-04-26 22:39:08 -04:00
at91_can.c drivers: net: generalize napi_complete_done() 2017-01-30 15:10:42 -05:00
bfin_can.c can: remove obsolete assignment for CAN protocol error type 2015-11-23 09:37:38 +01:00
dev.c can: dev: add CAN interface API for fixed bitrates 2017-01-24 13:52:00 +01:00
flexcan.c can: flexcan: fix typo in comment 2017-03-03 13:00:07 +01:00
grcan.c docs: fix locations of several documents that got moved 2016-10-24 08:12:35 -02:00
janz-ican3.c drivers: net: generalize napi_complete_done() 2017-01-30 15:10:42 -05:00
Kconfig can: add Virtual CAN Tunnel driver (vxcan) 2017-04-25 09:04:30 +02:00
led.c
Makefile can: add Virtual CAN Tunnel driver (vxcan) 2017-04-25 09:04:30 +02:00
pch_can.c can: fix assignment of error location in CAN error messages 2015-11-23 09:37:34 +01:00
rx-offload.c can: rx-offload: Add support for timestamp based irq offloading 2017-02-06 15:13:24 +01:00
slcan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
sun4i_can.c can: remove obsolete assignment for CAN protocol error type 2015-11-23 09:37:38 +01:00
ti_hecc.c can: ti_hecc: fix return value check in ti_hecc_probe() 2017-04-25 10:03:40 +02:00
vcan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
vxcan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
xilinx_can.c drivers: net: generalize napi_complete_done() 2017-01-30 15:10:42 -05:00