usb: gadget: Fix net_device lifecycles and configfs races
Get series with b4
b4 am [email protected] change-id 20260320-usb-net-lifecycle-cd5911d7e013Versions newest first
- v1 Latest7 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | usb: gadget: f_subset: Fix unbalanced refcnt in geth_freedrivers/ | +6 | 0 replies | |
| 2/7 | usb: gadget: f_rndis: Protect RNDIS options with mutexdrivers/ | +6 | 0 replies | |
| 3/7 | usb: gadget: u_ncm: Add kernel-doc comments for struct f_ncm_optsdrivers/ | +15 | 0 replies | |
| 4/7 | usb: gadget: f_ecm: Fix net_device lifecycle with device_movedrivers/ drivers/ | +39 | 0 replies | |
| 5/7 | usb: gadget: f_eem: Fix net_device lifecycle with device_movedrivers/ drivers/ | +46 | 0 replies | |
| 6/7 | usb: gadget: f_subset: Fix net_device lifecycle with device_movedrivers/ drivers/ | +44 | 0 replies | |
| 7/7 | usb: gadget: f_rndis: Fix net_device lifecycle with device_movedrivers/ drivers/ | +48 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/7] usb: gadget: Fix net_device lifecycles and configfs races
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.
---
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,
Signature · 1 line
Kuen-Han Tsai <[email protected]>