linux/drivers/usb/gadget/function
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
..
f_acm.c usb: gadget: acm: fix endianness in notifications 2017-03-22 11:20:52 +02:00
f_ecm.c
f_eem.c
f_fs.c usb: gadget: f_fs: avoid out of bounds access on comp_desc 2017-05-16 14:11:04 +03:00
f_hid.c usb: gadget: f_hid: fix: Don't access hidg->req without spinlock held 2017-03-22 11:21:10 +02:00
f_loopback.c
f_mass_storage.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
f_mass_storage.h
f_midi.c
f_ncm.c drivers: add explicit interrupt.h includes 2017-03-30 11:05:34 -07:00
f_obex.c
f_phonet.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
f_printer.c usb: gadget: printer: Remove pnp_string static buffer 2017-01-24 11:04:08 +02:00
f_rndis.c
f_serial.c
f_sourcesink.c
f_subset.c
f_tcm.c usb: gadget: Correct usb EP argument for BOT status request 2017-03-30 01:36:50 -07:00
f_uac1.c
f_uac2.c usb: gadget: uac2: add req_number as parameter 2017-01-24 11:04:21 +02:00
f_uvc.c usb: gadget: f_uvc: Sanity check wMaxPacketSize for SuperSpeed 2017-03-22 11:21:09 +02:00
f_uvc.h
g_zero.h
Makefile
ndis.h
rndis.c usb: gadget: Fix checkpatch error for braces 2016-11-18 13:54:41 +02:00
rndis.h usb: gadget: Fix checkpatch error for braces 2016-11-18 13:54:41 +02:00
storage_common.c
storage_common.h
tcm.h
u_ecm.h
u_eem.h
u_ether_configfs.h usb: gadget: ether: Add \n to each attribute of ethernet functions 2017-01-24 11:04:07 +02:00
u_ether.c usb: gadget: u_ether: conditionally align transfer size 2017-04-11 10:58:21 +03:00
u_ether.h
u_fs.h usb: changes for v4.12 2017-04-11 16:47:26 +02:00
u_gether.h
u_hid.h
u_midi.h
u_ncm.h
u_phonet.h
u_printer.h usb: gadget: printer: Remove pnp_string static buffer 2017-01-24 11:04:08 +02:00
u_rndis.h
u_serial.c usb: gadget: gserial: check if console kthread exists 2017-05-16 14:11:04 +03:00
u_serial.h
u_tcm.h
u_uac1.c
u_uac1.h
u_uac2.h usb: gadget: uac2: add req_number as parameter 2017-01-24 11:04:21 +02:00
u_uvc.h
uvc_configfs.c usb: gadget: uvc: Missing files for configfs interface 2017-04-11 10:57:59 +03:00
uvc_configfs.h
uvc_queue.c
uvc_queue.h
uvc_v4l2.c usb: gadget: Fix checkpatch error for braces 2016-11-18 13:54:41 +02:00
uvc_v4l2.h
uvc_video.c usb: gadget: composite: always set ep->mult to a sensible value 2016-10-31 11:15:33 +02:00
uvc_video.h
uvc.h usb: gadget: Fix checkpatch error for braces 2016-11-18 13:54:41 +02:00