mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kuen-Han Tsai <khtsai@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@ti.com>,
	 Prashanth K <prashanth.k@oss.qualcomm.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	 Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Kuen-Han Tsai <khtsai@google.com>,
	stable@kernel.org
Subject: [PATCH 0/3] usb: gadget: Refactor NCM net_device lifecycle
Date: Tue, 30 Dec 2025 18:13:13 +0800	[thread overview]
Message-ID: <20251230-ncm-refactor-v1-0-793e347bc7a7@google.com> (raw)

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@google.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@google.com>


             reply	other threads:[~2025-12-30 10:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-30 10:13 Kuen-Han Tsai [this message]
2025-12-30 10:13 ` [PATCH 1/3] usb: gadget: u_ether: add gether_opts for config caching Kuen-Han Tsai
2025-12-30 10:13 ` [PATCH 2/3] usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device Kuen-Han Tsai
2025-12-30 10:13 ` [PATCH 3/3] usb: gadget: f_ncm: align net_device lifecycle with bind/unbind Kuen-Han Tsai
2026-01-09 10:25   ` Ernest Van Hoecke
2026-01-09 10:47     ` Kuen-Han Tsai
2026-02-28 21:44   ` David Heidelberg
2026-03-09 10:20   ` Jon Hunter
2026-03-09 10:37     ` Kuen-Han Tsai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251230-ncm-refactor-v1-0-793e347bc7a7@google.com \
    --to=khtsai@google.com \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=prashanth.k@oss.qualcomm.com \
    --cc=stable@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®