linux/net/batman-adv
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
..
bat_algo.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_algo.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_iv_ogm.c This feature/cleanup patchset includes the following patches: 2017-04-06 14:37:50 -07:00
bat_iv_ogm.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_v_elp.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_v_elp.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_v_ogm.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_v_ogm.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bat_v.c Here are two batman-adv bugfixes: 2017-03-16 12:05:38 -07:00
bat_v.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bitarray.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bitarray.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
bridge_loop_avoidance.c batman-adv: handle race condition for claims between gateways 2017-03-22 10:30:53 +01:00
bridge_loop_avoidance.h batman-adv: prevent multiple ARP replies sent by gateways if dat enabled 2017-03-22 10:30:53 +01:00
debugfs.c batman-adv: Fix includes for IS_ERR/ERR_PTR 2017-01-28 10:40:35 +01:00
debugfs.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
distributed-arp-table.c batman-adv: Use net_device_stats from struct net_device 2017-04-05 15:41:24 +02:00
distributed-arp-table.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
fragmentation.c Here are two batman-adv bugfixes: 2017-03-16 12:05:38 -07:00
fragmentation.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
gateway_client.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
gateway_client.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
gateway_common.c Here are two batman-adv bugfixes: 2017-03-16 12:05:38 -07:00
gateway_common.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
hard-interface.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
hard-interface.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
hash.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
hash.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
icmp_socket.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
icmp_socket.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
Kconfig batman-adv: Allow selecting BATMAN V if CFG80211 is not built 2016-10-17 16:28:48 +02:00
log.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
log.h batman-adv: Fix possible side-effects in _batadv_dbg 2017-03-16 21:14:52 +01:00
main.c batman-adv: restructure rebroadcast counter into forw_packet API 2017-03-26 12:46:44 +02:00
main.h batman-adv: Convert BATADV_PRINT_VID macro to function 2017-03-16 21:14:53 +01:00
Makefile batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
multicast.c batman-adv: Reduce preprocessor checks in multicast.c 2017-03-16 21:14:50 +01:00
multicast.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
netlink.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
netlink.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
network-coding.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
network-coding.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
originator.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
originator.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
packet.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
routing.c batman-adv: changed debug messages for easier bla debugging 2017-03-22 10:30:53 +01:00
routing.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
send.c batman-adv: restructure rebroadcast counter into forw_packet API 2017-03-26 12:46:44 +02:00
send.h batman-adv: restructure rebroadcast counter into forw_packet API 2017-03-26 12:46:44 +02:00
soft-interface.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
soft-interface.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
sysfs.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
sysfs.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
tp_meter.c batman-adv: Use __func__ to add function names to messages 2017-03-17 12:53:35 +01:00
tp_meter.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
translation-table.c batman-adv: Convert BATADV_PRINT_VID macro to function 2017-03-16 21:14:53 +01:00
translation-table.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
tvlv.c batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
tvlv.h batman-adv: update copyright years for 2017 2017-01-26 08:34:19 +01:00
types.h This feature/cleanup patchset includes the following patches: 2017-04-06 14:37:50 -07:00