From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A5872DBF40 for ; Tue, 30 Dec 2025 10:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767089613; cv=none; b=KUZIreNKfLeVH8rhcoGCWbGqEHceEXmfBYNJfikgm4ZCwI2IYKgtMSYoMUvNQ78OEZmE4dKMVpahi3O3JpwEQnCbTGI5cyR0jnl25GA/AXNXXeHnZwYeKCoP3x7+Q65DJ9nfriSXMsxmYx2V6z5SLNseHO9ALxIXbCnQH+SGf30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767089613; c=relaxed/simple; bh=GqjS8NhsN2P/EGV88kKMv9onh82daaNIe8QViAbDeFA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=lBrq2WN8F4lNS/AjFh8Puok7Vlk6++PFg4AZ7+RfBNBBScm490qlpDnsLD07SwqYWawWbnThPifQPjjFmJshCpzmue8ZIkSsjn8wh7p0CCm0Qq0SeDUnlYo5xXxVm2ZF+aA2xbGHYDddVm4gvIj3Jeeqo54jw3Az6+KLPKjLWfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--khtsai.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NIuSXd9t; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--khtsai.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NIuSXd9t" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7f89d880668so14422663b3a.2 for ; Tue, 30 Dec 2025 02:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767089611; x=1767694411; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=urNf4tibA/ClGGMLFCybJdJKvxoBLt6em6cEb4hXuC0=; b=NIuSXd9tc+3zTHD2560j/qvv8P6tFIbZGLarC1LufUG0MJHepvtRBF8NJDVk+R4AR0 oOb6ddUUy356fKR+g5L88Qu6vYtWRg9pe0+LmgVKBxeWDq3UNhYcYfB5uUfld28Lc+m3 bPhgRywkfqzba+a5Ij3iAo639C4DoBpFaRIlYoHp2XmvJ9WELy9LgmpLizAqP+zpNbD7 13OqT9faEdR1O+7zavgcOAgKd4NX7YpBcX/AVLzz+fRbhOY7/4nR6O+j8qqAj9ikubWb yhpfrVaO4q6MydEhu4H5ARAFAAjVkLeLg2C0YPsoQithQpF3dBHlnq/AAu/BSUPFKraO TLag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767089611; x=1767694411; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=urNf4tibA/ClGGMLFCybJdJKvxoBLt6em6cEb4hXuC0=; b=fZWbb41Yh0+n5xX0uJTP3PwZ8XZ5Po3FTWqr3lFaOTUJTH1r8lYYDEFpSdz/bfg92w UJT6pKymbz9d+d4vgoGjBALb0AmZdjVk4xgxAgJPo4YsB8mPEs4AoVaVu567qWi13kA0 6TJASnvPdTKkrSCDNX/VnIhhes+SQxfQeNzk4z0+cA5FGlahOwMl+N4t8shk/3EJJQlk pRwmW+zH1l1DN4OnJ6f7o062tn9gIYmYZ4lXhjO62sZx3yjhrMaSkgytAkRd8+EMMiNI muJh0JRkPumJJGLqj1ntCWOVp8o6SNeWkXjMkWhRbIt1LmiZaZJ6WOVwYqmfN1dGJN0l YyFQ== X-Forwarded-Encrypted: i=1; AJvYcCUdNb+cu3IExNbJo1vb+maUIfBMyb6oVZnocmJ6BkM+oqCmOKA9qXqW4+PZSVdZRnTWWiIiAFm1Rg0iWjI=@vger.kernel.org X-Gm-Message-State: AOJu0YyGgSTHEdIIfOmgNQjqmxTcjDHB5KmWWxcTlZt2suUwUKJiT5Uz oUDbYl4UWuYf764Y5VxVVjAW7S843i9sac2Kv1P7PeKAynH4j+NBzOgY/ugTzl6QUf2E03LSl0G f+SdJAQ== X-Google-Smtp-Source: AGHT+IFuEt4dfp5NeDiOEVezMAfxVhj7x2iY5wCwSqw2kjLdIRp4jrbxbujwgbHzxeCxyqprmF8jKrEyDHQ= X-Received: from pfdr5.prod.google.com ([2002:aa7:8b85:0:b0:77e:32f7:68cd]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4392:b0:7e8:4398:b351 with SMTP id d2e1a72fcca58-7ff66079db6mr25933079b3a.36.1767089611501; Tue, 30 Dec 2025 02:13:31 -0800 (PST) Date: Tue, 30 Dec 2025 18:13:13 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALmlU2kC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1NDI2MD3bzkXN2i1LTE5JL8Il1LC4s0y0SzFBNTS0MloJYCoExmBdi46Nj aWgDNx154XgAAAA== X-Change-Id: 20251230-ncm-refactor-988f9a6d4591 X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1767089609; l=2412; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=GqjS8NhsN2P/EGV88kKMv9onh82daaNIe8QViAbDeFA=; b=AbW/6gIYS6dUtdNHdwNzGMmYpR74iMN1U1MWdqIoFUDMP2XXl613rVEf5hkhz63aTJlDWjq2g e2qMWFM8l1CDuoJPYJBmkFCo6AHWUybbL8cUoiRbdfXOVPwkCfzNDCO X-Mailer: b4 0.14.2 Message-ID: <20251230-ncm-refactor-v1-0-793e347bc7a7@google.com> Subject: [PATCH 0/3] usb: gadget: Refactor NCM net_device lifecycle From: Kuen-Han Tsai To: Greg Kroah-Hartman , Felipe Balbi , Prashanth K , Kyungmin Park , Andrzej Pietrasiewicz Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kuen-Han Tsai , stable@kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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