[PATCH 0/7] usb: gadget: Fix net_device lifecycles and configfs races
From: Kuen-Han Tsai
Date: Fri Mar 20 2026 - 04:57:40 EST
Hi all,
This patch series addresses dangling sysfs symlink issues across the
remaining USB gadget network functions (f_ecm, f_eem, f_subset, and
f_rndis). It also includes configfs concurrency and reference-counting
bug fixes identified during the investigation.
Commit ec35c1969650 ("usb: gadget: f_ncm: Fix net_device lifecycle
with device_move") introduced an architectural fix for f_ncm to resolve
an issue where unbinding the function resulted in the net_device
surviving the destruction of its gadget parent device. This lifecycle
mismatch leaves dangling sysfs symlinks:
console:/ # ls -l /sys/class/net/usb0
lrwxrwxrwx ... /sys/class/net/usb0 ->
/sys/devices/platform/.../gadget.0/net/usb0
console:/ # ls -l /sys/devices/platform/.../gadget.0/net/usb0
ls: .../gadget.0/net/usb0: No such file or directory
This series applies the same device_move() pattern to the rest of the
USB network functions. Temporarily moving the net_device to
/sys/devices/virtual during unbind, and re-parenting it back to the new
gadget device during bind, restores proper sysfs topology without
leaking references or breaking legacy composite drivers (like multi.c).
To ensure safe teardown and avoid regressing legacy composite drivers
that manually pre-register net_devices, the bound and borrowed_net
flags now strictly indicate if the device was shared and
pre-registered during the legacy driver's bind phase.
Patch Summary:
- Patches 1-2: Fix an unbalanced reference count in f_subset and add a
missing configfs mutex lock for RNDIS options.
- Patch 3: Add comprehensive kernel-doc descriptions for struct
f_ncm_opts to match the standard applied to the other functions.
- Patches 4-7: Implement the device_move() lifecycle fix consistently
across f_ecm, f_eem, f_subset, and f_rndis.
Signed-off-by: Kuen-Han Tsai <khtsai@xxxxxxxxxx>
---
Kuen-Han Tsai (7):
usb: gadget: f_subset: Fix unbalanced refcnt in geth_free
usb: gadget: f_rndis: Protect RNDIS options with mutex
usb: gadget: u_ncm: Add kernel-doc comments for struct f_ncm_opts
usb: gadget: f_ecm: Fix net_device lifecycle with device_move
usb: gadget: f_eem: Fix net_device lifecycle with device_move
usb: gadget: f_subset: Fix net_device lifecycle with device_move
usb: gadget: f_rndis: Fix net_device lifecycle with device_move
drivers/usb/gadget/function/f_ecm.c | 37 +++++++++++++-------
drivers/usb/gadget/function/f_eem.c | 59 ++++++++++++++++---------------
drivers/usb/gadget/function/f_rndis.c | 51 ++++++++++++++++-----------
drivers/usb/gadget/function/f_subset.c | 63 +++++++++++++++++++---------------
drivers/usb/gadget/function/u_ecm.h | 21 ++++++++----
drivers/usb/gadget/function/u_eem.h | 21 ++++++++----
drivers/usb/gadget/function/u_gether.h | 22 ++++++++----
drivers/usb/gadget/function/u_ncm.h | 21 ++++++++----
drivers/usb/gadget/function/u_rndis.h | 31 ++++++++++++-----
9 files changed, 204 insertions(+), 122 deletions(-)
---
base-commit: f50200dd44125e445a6164e88c217472fa79cdbc
change-id: 20260320-usb-net-lifecycle-cd5911d7e013
Best regards,
--
Kuen-Han Tsai <khtsai@xxxxxxxxxx>