[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251230-ncm-refactor-v1-0-793e347bc7a7@google.com>
Date: Tue, 30 Dec 2025 18:13:13 +0800
From: Kuen-Han Tsai <khtsai@...gle.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Felipe Balbi <balbi@...com>,
Prashanth K <prashanth.k@....qualcomm.com>, Kyungmin Park <kyungmin.park@...sung.com>,
Andrzej Pietrasiewicz <andrzej.p@...sung.com>
Cc: linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
Kuen-Han Tsai <khtsai@...gle.com>, stable@...nel.org
Subject: [PATCH 0/3] usb: gadget: Refactor NCM net_device lifecycle
Refactor the network device lifecycle management within the USB gadget
NCM function and the underlying u_ether library.
The primary goal is to align the net_device lifetime with the USB
function's bind/unbind events rather than the function instance
allocation/deallocation. This resolves issues with dangling sysfs
symbolic links and potential use-after-free scenarios when the gadget is
disconnected, as the net_device could previously outlive its parent
gadget device.
Other gadget function drivers using u_ether (e.g., ECM, EEM, RNDIS) may
have similar net_device lifecycle mismatches. While not addressed in
this series, they could potentially benefit from a similar refactoring
in the future.
The series is structured as follows:
1. u_ether: add gether_opts for config caching: Introduce a new struct
gether_opts to cache network settings (MAC addresses, ifname, etc.)
from configfs independently of the net_device. This allows deferring
net_device creation to the bind phase without losing pre-configuration
capabilities.
2. u_ether: Add auto-cleanup helper for freeing net_device: Introduce
gether_unregister_free_netdev() and DEFINE_FREE to support auto-cleanup
for net_device within the bind path, preparing for net_device allocation
changes in f_ncm.
3. f_ncm: align net_device lifecycle with bind/unbind: The main patch
that moves net_device allocation/registration into ncm_bind() and
unregistration/freeing into ncm_unbind(). It utilizes the gether_opts
for applying cached settings and the new cleanup helper.
Signed-off-by: Kuen-Han Tsai <khtsai@...gle.com>
---
Kuen-Han Tsai (3):
usb: gadget: u_ether: add gether_opts for config caching
usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device
usb: gadget: f_ncm: align net_device lifecycle with bind/unbind
drivers/usb/gadget/function/f_ncm.c | 128 +++++++++---------
drivers/usb/gadget/function/u_ether.c | 45 +++++++
drivers/usb/gadget/function/u_ether.h | 30 +++++
drivers/usb/gadget/function/u_ether_configfs.h | 176 +++++++++++++++++++++++++
drivers/usb/gadget/function/u_ncm.h | 4 +-
5 files changed, 317 insertions(+), 66 deletions(-)
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251230-ncm-refactor-988f9a6d4591
Best regards,
--
Kuen-Han Tsai <khtsai@...gle.com>
Powered by blists - more mailing lists