linux/drivers/usb/gadget/function
Kuen-Han Tsai ec35c19696 usb: gadget: f_ncm: Fix net_device lifecycle with device_move
The network device outlived its parent gadget device during
disconnection, resulting in dangling sysfs links and null pointer
dereference problems.

A prior attempt to solve this by removing SET_NETDEV_DEV entirely [1]
was reverted due to power management ordering concerns and a NO-CARRIER
regression.

A subsequent attempt to defer net_device allocation to bind [2] broke
1:1 mapping between function instance and network device, making it
impossible for configfs to report the resolved interface name. This
results in a regression where the DHCP server fails on pmOS.

Use device_move to reparent the net_device between the gadget device and
/sys/devices/virtual/ across bind/unbind cycles. This preserves the
network interface across USB reconnection, allowing the DHCP server to
retain their binding.

Introduce gether_attach_gadget()/gether_detach_gadget() helpers and use
__free(detach_gadget) macro to undo attachment on bind failure. The
bind_count ensures device_move executes only on the first bind.

[1] https://lore.kernel.org/lkml/f2a4f9847617a0929d62025748384092e5f35cce.camel@crapouillou.net/
[2] https://lore.kernel.org/linux-usb/795ea759-7eaf-4f78-81f4-01ffbf2d7961@ixit.cz/

Fixes: 40d133d7f5 ("usb: gadget: f_ncm: convert to new function interface with backward compatibility")
Cc: stable <stable@kernel.org>
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Link: https://patch.msgid.link/20260309-f-ncm-revert-v2-7-ea2afbc7d9b2@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-03-11 16:21:19 +01:00
..
Makefile usb: gadget: uvc: add trace of enqueued and completed requests 2024-10-17 08:42:23 +02:00
f_acm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_ecm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_eem.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_fs.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_hid.c usb: gadget: f_hid: fix SuperSpeed descriptors 2026-03-11 16:17:29 +01:00
f_loopback.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_mass_storage.c usb: gadget: f_mass_storage: Fix potential integer overflow in check_command_size_in_blocks() 2026-03-11 16:17:44 +01:00
f_mass_storage.h USB: gadget: fix up const issue with struct usb_function_instance 2025-05-23 12:31:34 +02:00
f_midi.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
f_midi2.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
f_ncm.c usb: gadget: f_ncm: Fix net_device lifecycle with device_move 2026-03-11 16:21:19 +01:00
f_obex.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_phonet.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_printer.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_rndis.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_serial.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_sourcesink.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_subset.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_tcm.c usb: gadget: f_tcm: Fix NULL pointer dereferences in nexus handling 2026-02-23 20:22:00 +01:00
f_uac1.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_uac1_legacy.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_uac2.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_uvc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
f_uvc.h usb: gadget: uvc: prevent use of disabled endpoint 2023-11-23 12:32:44 +00:00
g_zero.h usb: gadget: f_sourcesink: Support maxburst configurability for bulk endpoints 2026-01-07 16:13:25 +01:00
ndis.h
rndis.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
rndis.h
storage_common.c usb: gadget: add missing MODULE_DESCRIPTION() macros 2024-06-20 19:18:19 +02:00
storage_common.h usb: storage: add a macro for the upper limit of max LUN 2024-12-04 16:33:54 +01:00
tcm.h usb: gadget: f_tcm: Stall on invalid CBW 2024-12-24 08:56:07 +01:00
u_audio.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
u_audio.h
u_ecm.h
u_eem.h
u_ether.c usb: gadget: f_ncm: Fix net_device lifecycle with device_move 2026-03-11 16:21:19 +01:00
u_ether.h usb: gadget: f_ncm: Fix net_device lifecycle with device_move 2026-03-11 16:21:19 +01:00
u_ether_configfs.h Revert "usb: gadget: u_ether: add gether_opts for config caching" 2026-03-11 16:21:16 +01:00
u_fs.h functionfs: use spinlock for FFS_DEACTIVATED/FFS_CLOSING transitions 2026-02-05 13:53:12 -05:00
u_gether.h
u_hid.h usb: gadget: hid: allow dynamic interval configuration via configfs 2025-05-01 17:30:48 +02:00
u_midi.h usb: gadget: f_midi: allow customizing the USB MIDI interface string through configfs 2025-12-17 14:43:01 +01:00
u_midi2.h usb: gadget: midi2: More flexible MIDI 1.0 configuration 2023-07-26 06:38:14 +02:00
u_ncm.h usb: gadget: f_ncm: Fix net_device lifecycle with device_move 2026-03-11 16:21:19 +01:00
u_phonet.h usb: gadget: function: Remove unused declarations 2023-08-22 14:45:29 +02:00
u_printer.h
u_rndis.h
u_serial.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
u_serial.h usb: gadget: f_acm: make bInterfaceProtocol configurable 2024-09-03 09:54:16 +02:00
u_tcm.h
u_uac1.h usb: gadget: f_uac1: Change volume name and remove alt names 2024-08-13 18:11:35 +02:00
u_uac1_legacy.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
u_uac1_legacy.h
u_uac2.h usb: gadget: f_uac2: Expose all string descriptors through configfs. 2024-08-13 10:37:05 +02:00
u_uvc.h usb: gadget: webcam: Make g_webcam loadable again 2023-12-15 18:27:38 +01:00
uac_common.h
uvc.h usb: gadget: uvc: fix interval_duration calculation 2026-01-14 16:03:17 +01:00
uvc_configfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
uvc_configfs.h usb: gadget: uvc: Avoid -Wflex-array-member-not-at-end warnings 2025-04-11 16:08:33 +02:00
uvc_queue.c usb: gadget: uvc: retry vb2_reqbufs() with vb_vmalloc_memops if use_sg fail 2026-01-14 16:03:18 +01:00
uvc_queue.h usb: gadget: uvc: set req_length based on payload by nreqs instead of req_size 2024-10-17 08:42:22 +02:00
uvc_trace.c usb: gadget: uvc: add trace of enqueued and completed requests 2024-10-17 08:42:23 +02:00
uvc_trace.h usb: gadget: uvc: add trace of enqueued and completed requests 2024-10-17 08:42:23 +02:00
uvc_v4l2.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
uvc_v4l2.h
uvc_video.c usb: gadget: uvc: fix interval_duration calculation 2026-03-11 16:19:04 +01:00
uvc_video.h usb: gadget: uvc: move video disable logic to its own function 2023-11-23 12:32:44 +00:00