From nobody Sun Feb 8 14:12:44 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 264D4293C44 for ; Tue, 30 Dec 2025 10:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767089618; cv=none; b=kOKnLAT0m+dYuySTmVuVh4fZ+wlrIA2A/yzI09sEOxwP/9ILwrH4yeiXv5nWoqQAFuxbdbpSoTrBwcDdn0YyPmkrFRsk6Zw9RZY776Cf1/4KH3rURBQOsExK+97MurZYoBlnz+WUPsI6vUjpmFgvmzn9XVEG0Pi/Kle8caBTx/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767089618; c=relaxed/simple; bh=bFTNHGlATa0Hla5Mbg6BP8YN6e6iG4/i1alM7w8QGgs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UtxrxejMQXCbbgPC8uIvJztD8i1GYAg6eeJ45J83KaUkrE4dH9jv7zAg7lk9oA4k9E0w9joBs+koalHa9vdDDy4f+cx3AyylU3GxxmbK3juBQri6EsykbplhCd+DPBPaPwQlw8hGTp96Qxcl3wn5Sy/BNIkPRrKJ9hoL1hLulU0= 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=KUZn6Z/6; arc=none smtp.client-ip=209.85.216.74 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="KUZn6Z/6" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34c21341f56so29535947a91.2 for ; Tue, 30 Dec 2025 02:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767089615; x=1767694415; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8jOZKIuCkqJHkqWCHRB+SikfdpIuZqSJJtfkMgy1p+g=; b=KUZn6Z/6n/DMDAGbpRLV7O70rf2a8eseHThGmhD2Xh9YFTnM2qBRmmyXPXMrDCIwwC L1qH/k/HJ2jTVjt1ZBKcu3xd3PB7uhg2PmIMbTBMSSE1sZbyD1Tan0pN3klKkJGaPykq b/Mj9xv9SYbKMx2cnFS3BQ5wDMC7Cwkj3KVus67VINbKAWyVGqk9F9jiOvY7r1k7RxYq i+gsW33rhxX6lZdlEN0PuPbPv4/aPU0W6+5CIK8I27XsSC1GNJ615AwVfFObgmFGUKSw 9jyk9zJcQHshNvTE5xlPHtAMSTRirNo+rrg/Qc7H3nOjvtZZ8VCG6q9/4pDys/NBtqvx ntbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767089615; x=1767694415; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8jOZKIuCkqJHkqWCHRB+SikfdpIuZqSJJtfkMgy1p+g=; b=B548ZpXQr6vZu6H5XX/zdJj4avV4ipLm/VOZ8zoe5+XUINqjRC6cjVLaXGGfemJ26j 89jvlDgK05ECm7DVs4fMKZkwmAsvElY80DGSYhzTbArZ2yZQRm3/govgMqe3gg64a41u lZoLLNUPcNYvf9vNsLK8oJFw/jmFnZLF9AE+D6FNzQQgnxn+DxRkA7+Qf25VHzQ3T8+3 cjBrI+2rIZpYGP0XASvkTUT4HOFXtP3ZRq1Hd3Ga2ZpnmJEbtoZLH5ONjNC/b2aogwjG iyZT3+DOCMGihQJE6Jn+AidG14RDiSBSoNv2UVlJIp8imdlSxz82WvMFzMn/ABmcWNIJ uOWg== X-Forwarded-Encrypted: i=1; AJvYcCVJtMRMoYsgd3XUBvileix/rroI045VQMQhxDBNxDthKMGLUQJ4f3B+uU7BDde3dRNPxWtEfzLR2EFIPLk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+OCtRgXrsyQ8x13j3I4VqT2KQnJ7Ze/ctYu+2UJxz2GY8PZbk +EbZD4k7XD9VHvWJsl66maRdr39EHTTa6/Cy0xggKmzjWhk1rYZ2sklXeyt4nWaRoVfCD8y6oof zcAwNig== X-Google-Smtp-Source: AGHT+IEImhiwIBtyB9uwTQWMXDP5sO/acuizF4Z0INFLRG+6D1/NhX/w6UmGzfdzHf2E2R2GylIIrUw5nbs= X-Received: from pgag25.prod.google.com ([2002:a05:6a02:2f19:b0:c06:531d:e55b]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:32aa:b0:366:14b0:1a2f with SMTP id adf61e73a8af0-376aabfca96mr31871828637.61.1767089615374; Tue, 30 Dec 2025 02:13:35 -0800 (PST) Date: Tue, 30 Dec 2025 18:13:15 +0800 In-Reply-To: <20251230-ncm-refactor-v1-0-793e347bc7a7@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251230-ncm-refactor-v1-0-793e347bc7a7@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1767089609; l=2399; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=bFTNHGlATa0Hla5Mbg6BP8YN6e6iG4/i1alM7w8QGgs=; b=sTNA+otnvqWmULvk2FmT51uy43fDZXUjva8mkEZNFZkqmy436EtKiNFWRjGUn9TJzMP5b6+SA 5Tehw6IpdSqBKlQrErEJEr9ykXOyCjMVq28RKFpz0DRHa2j76+vR9vo X-Mailer: b4 0.14.2 Message-ID: <20251230-ncm-refactor-v1-2-793e347bc7a7@google.com> Subject: [PATCH 2/3] usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The net_device in the u_ether framework currently requires explicit calls to unregister and free the device. Introduce gether_unregister_free_netdev() and the corresponding auto-cleanup macro. This ensures that if a net_device is registered, it is properly unregistered and the associated work queue is flushed before the memory is freed. This is a preparatory patch to simplify error handling paths in gadget drivers by removing the need for explicit goto labels for net_device cleanup. Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/function/u_ether.c | 15 +++++++++++++++ drivers/usb/gadget/function/u_ether.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/fun= ction/u_ether.c index 745ed2c212e3a706b0e6725731b42d34428f8b22..6c32665538cc0dcbce8e73ec8ea= 573b04c720386 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -1125,6 +1125,21 @@ void gether_cleanup(struct eth_dev *dev) } EXPORT_SYMBOL_GPL(gether_cleanup); =20 +void gether_unregister_free_netdev(struct net_device *net) +{ + if (!net) + return; + + struct eth_dev *dev =3D netdev_priv(net); + + if (net->reg_state =3D=3D NETREG_REGISTERED) { + unregister_netdev(net); + flush_work(&dev->work); + } + free_netdev(net); +} +EXPORT_SYMBOL_GPL(gether_unregister_free_netdev); + /** * gether_connect - notify network layer that USB link is active * @link: the USB link, set up with endpoints, descriptors matching diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/fun= ction/u_ether.h index 63a0240df4d749bd91c9dd6743406075093a3168..a212a8ec5eb1b920d53fadc7a0e= 0e80e18db8ba9 100644 --- a/drivers/usb/gadget/function/u_ether.h +++ b/drivers/usb/gadget/function/u_ether.h @@ -283,6 +283,8 @@ int gether_get_ifname(struct net_device *net, char *nam= e, int len); int gether_set_ifname(struct net_device *net, const char *name, int len); =20 void gether_cleanup(struct eth_dev *dev); +void gether_unregister_free_netdev(struct net_device *net); +DEFINE_FREE(free_gether_netdev, struct net_device *, gether_unregister_fre= e_netdev(_T)); =20 void gether_setup_opts_default(struct gether_opts *opts, const char *name); void gether_apply_opts(struct net_device *net, struct gether_opts *opts); --=20 2.52.0.351.gbe84eed79e-goog