From nobody Wed Apr 15 16:43:55 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 963E436DA09 for ; Wed, 4 Mar 2026 07:11:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608281; cv=none; b=LmkAkSnJHeCrxhQ0tPzWp2zvRM9Q/TDcwpVlngkkJvMnl9CKdaO9v5alUvnmrWa5yymcCs4TfFnsgXBBhWEFClBlpElyM0imYYd1Rd5UwzMp8FI4w1+Tk4hFLpE3lhdeQXLI5NZxnQJSAtIdUN/8fyBlDOrRtcfbqdezlt3ykx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608281; c=relaxed/simple; bh=5/YxhynNP5OtTJz20C93GRmdTUgl+LzpEZyjUYK3nk0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WQ3YPiOCADGXGzl1NTkWooVmDDWt6yvJKhwsQF6bfHY3zdagDukky8KKNYe2tlvJioyP0swLUXSoPiui6Hjh/ZByaldjnYUJ48MmLwaY0RS09x88XyDY1IwdjT5aLSWeC9ftbbi4Ues3sYcG30+ciXFbsGzfcTwlu/I2Cuni3tI= 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=MrPDbLTu; arc=none smtp.client-ip=209.85.215.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="MrPDbLTu" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c709551ec08so24575022a12.3 for ; Tue, 03 Mar 2026 23:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608280; x=1773213080; 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=Up+QEdUkj26uFbINRayYsiYrdHXv4LEpi2MdfDCCm0k=; b=MrPDbLTu3Od2JI0eCagz3AROGG5NDiONyCd9oD+f+ThQuE1E7RT7/WMFibmuTmsfVI Skr9/7VkTvmaMd0z4IhJtze9YrTRi5cUPhgDWJSY4RTV/31l8R9hCJ1nldlbYkR7Xlqi vfes3x3/4cGzCXSvZ7NqAyi6BIvURngdW6jR4Rk4DqwqyDGSi8TQ8rQcpoKtFMiz7+1d LNeN2jwZyeH8oZ229H9GkCYjErin0ksPLRy4Fm5webs5TJwRUaIjLyb4VMRbPARUXoUW y9cvGrmIiXXIffa7nemQUDfL2Yzviza36UDscwTgJuv5Cay8PtboJdUviqdN+aUR7Dr0 OEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608280; x=1773213080; 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=Up+QEdUkj26uFbINRayYsiYrdHXv4LEpi2MdfDCCm0k=; b=nMcvhafTDKop8dmZXHabtDcA+HubvPN0p6YDEcNC9AL/eay73BE8CPvQYgLlJAZaJJ HM6NCIvgbIZmT2SYdvxzlaUjcuTovtm7uOAxK/rNkzCysNDk6WKsCLdQOzKg35EUJCwE uO/aTA2AvDLpB97squ5sgNh3sAqM3qeGsjjDoDDwbwR0dexJqF8os4NeOIwBnWTyMHQm /82WmUxJgyv916CllyxEXFwAJ/IV5e79NVKlMVHAGCF10gF9oD5dbZFXT7e+b3fJ7w60 WQaeFx02RCDutZTJj/VXSEd6kYm2230SGuiTtRfHpJjfj4FsFTV34FUK7aBo4+5p5iDA VaaQ== X-Forwarded-Encrypted: i=1; AJvYcCUKfhUQgeixen/u+c0bLCiPWU1woQD/ESBonbmBqI+5xXyGfLxExkUERw7AE4ZtdA1oA0wgH/uTOWxU7/4=@vger.kernel.org X-Gm-Message-State: AOJu0YyjHAmnPN6ahcq2dsK7oZPlDgEHX7muiw1wHqsOVNasIccqgtuZ HCUywTX29lppl6h6eKEXyPnZGphEJjLlhPyvrT2+UHKP7hDSOssoBp1uoS0/J1vBIfETWYdI06Y 2maERtA== X-Received: from pgbfq8.prod.google.com ([2002:a05:6a02:2988:b0:bd9:a349:94b7]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:193:b0:389:8f3f:50d0 with SMTP id adf61e73a8af0-3982e2a9a32mr1160280637.60.1772608279770; Tue, 03 Mar 2026 23:11:19 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:53 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=5610; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=5/YxhynNP5OtTJz20C93GRmdTUgl+LzpEZyjUYK3nk0=; b=g4C1E6KH+LgB1Ro27j6zzmbqqjEt0rfvWsfWQ/nU8Ll9m8RXZ+bVYGYXZtTZsqJM38o68qQKF qwthj3ewpm9CV9/mpOuV+SY/T7pYtn9Qwt53b+SjJJ9dhqWgLIFErmy X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-1-57c9157b58af@google.com> Subject: [PATCH 1/6] Revert "usb: gadget: f_ncm: Fix atomic context locking issue" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , 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 This reverts commit 0d6c8144ca4d93253de952a5ea0028c19ed7ab68. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/function/f_ncm.c | 29 +++++++++++++++-------= ---- drivers/usb/gadget/function/u_ether_configfs.h | 11 +++++++++- drivers/usb/gadget/function/u_ncm.h | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/funct= ion/f_ncm.c index 4da19864d70b..14fc7dce6f39 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -58,7 +58,6 @@ struct f_ncm { u8 notify_state; atomic_t notify_count; bool is_open; - bool is_connected; =20 const struct ndp_parser_opts *parser_opts; bool is_crc; @@ -865,6 +864,7 @@ static int ncm_setup(struct usb_function *f, const stru= ct usb_ctrlrequest *ctrl) static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_ncm *ncm =3D func_to_ncm(f); + struct f_ncm_opts *opts =3D func_to_ncm_opts(f); struct usb_composite_dev *cdev =3D f->config->cdev; =20 /* Control interface has only altsetting 0 */ @@ -887,12 +887,13 @@ static int ncm_set_alt(struct usb_function *f, unsign= ed intf, unsigned alt) if (alt > 1) goto fail; =20 - if (ncm->is_connected) { - DBG(cdev, "reset ncm\n"); - ncm->is_connected =3D false; - gether_disconnect(&ncm->port); - ncm_reset_values(ncm); - } + scoped_guard(mutex, &opts->lock) + if (opts->net) { + DBG(cdev, "reset ncm\n"); + opts->net =3D NULL; + gether_disconnect(&ncm->port); + ncm_reset_values(ncm); + } =20 /* * CDC Network only sends data in non-default altsettings. @@ -925,7 +926,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned= intf, unsigned alt) net =3D gether_connect(&ncm->port); if (IS_ERR(net)) return PTR_ERR(net); - ncm->is_connected =3D true; + scoped_guard(mutex, &opts->lock) + opts->net =3D net; } =20 spin_lock(&ncm->lock); @@ -1372,14 +1374,16 @@ static int ncm_unwrap_ntb(struct gether *port, static void ncm_disable(struct usb_function *f) { struct f_ncm *ncm =3D func_to_ncm(f); + struct f_ncm_opts *opts =3D func_to_ncm_opts(f); struct usb_composite_dev *cdev =3D f->config->cdev; =20 DBG(cdev, "ncm deactivated\n"); =20 - if (ncm->is_connected) { - ncm->is_connected =3D false; - gether_disconnect(&ncm->port); - } + scoped_guard(mutex, &opts->lock) + if (opts->net) { + opts->net =3D NULL; + gether_disconnect(&ncm->port); + } =20 if (ncm->notify->enabled) { usb_ep_disable(ncm->notify); @@ -1683,6 +1687,7 @@ static struct usb_function_instance *ncm_alloc_inst(v= oid) if (!opts) return ERR_PTR(-ENOMEM); =20 + opts->net =3D NULL; opts->ncm_os_desc.ext_compat_id =3D opts->ncm_ext_compat_id; gether_setup_opts_default(&opts->net_opts, "usb"); =20 diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/g= adget/function/u_ether_configfs.h index 25d8fb05b598..217990a266b2 100644 --- a/drivers/usb/gadget/function/u_ether_configfs.h +++ b/drivers/usb/gadget/function/u_ether_configfs.h @@ -327,9 +327,18 @@ out: \ char *page) \ { \ struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ + const char *name; \ \ guard(mutex)(&opts->lock); \ - return sysfs_emit(page, "%s\n", opts->net_opts.name); \ + rtnl_lock(); \ + if (opts->net_opts.ifname_set) \ + name =3D opts->net_opts.name; \ + else if (opts->net) \ + name =3D netdev_name(opts->net); \ + else \ + name =3D "(inactive net_device)"; \ + rtnl_unlock(); \ + return sysfs_emit(page, "%s\n", name); \ } \ \ static ssize_t _f_##_opts_ifname_store(struct config_item *item, \ diff --git a/drivers/usb/gadget/function/u_ncm.h b/drivers/usb/gadget/funct= ion/u_ncm.h index 6d7538855744..d99330fe31e8 100644 --- a/drivers/usb/gadget/function/u_ncm.h +++ b/drivers/usb/gadget/function/u_ncm.h @@ -19,6 +19,7 @@ =20 struct f_ncm_opts { struct usb_function_instance func_inst; + struct net_device *net; =20 struct gether_opts net_opts; struct config_group *ncm_interf_group; --=20 2.53.0.473.g4a7958ca14-goog From nobody Wed Apr 15 16:43:55 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 811C437EFFB for ; Wed, 4 Mar 2026 07:11:22 +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=1772608283; cv=none; b=Q1BGNqyV8ujkVvwNJ2wg4P9ZJydD78r5NCrQMuKCMoRdtKXygn8ufWSEAS1oLpkIXZCf+2XikBFPvIoILxwDo9eBu746zJgDQYXkAqvKGKdnU5rZaw+b3Ol2TUVfhVPBnicShOQ+BnKZ6iJd97ry0jooO/8e8GYACuRkWi5/NGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608283; c=relaxed/simple; bh=hrijtfqfOvg8LYhTu0Jxjjl8F1NDkkXHNxjFaW5iGQQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lnbCBFrgWks/pzdJTm+FZ7DdAC/h3Ge1slbnGTu/kJHX1aEK0937BHfk90XlvBxGsilhkRjJZqNCfgc3+RfKLi7GF2e890aIxa4UTkSxs/onXybdyr0gfYBs6204S4nenGkyRU1qYP77gTD5bv+YT793W9J4iuRH/fCVjnIAxPk= 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=GdVf0lcz; 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="GdVf0lcz" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-354c44bf176so6065734a91.0 for ; Tue, 03 Mar 2026 23:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608282; x=1773213082; 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=TwK794DdqJYSdG6zV72tobi0ALWgKSn0ri9Q6Cr47G8=; b=GdVf0lcz4ZXnQefK6pSzMPqvxcZKxDQKV8OO5YlhJAx3CgYr2y7sLa6YlxUJ4606co 1wX9divv6nXK+avHSX+KNDE2A4TjMvYZB7lSyc8/wK4kyMhXU1g3OcAWKPk+q1gFNQde wvbkXMbjP8KysGl4Y9Yhrkf0nfuyWPZeDmiA8VcOwGlGPYdkrgiCIMkb+tHjqk50m5wO nthch9+LrFxMUiyx8zQTKaQCWtI/aHvW1CgzAE2g8KJSY901TgS3cieRshqsupSf2SRE /cxaVASh2ByMV986NXByIl2am5vnEj0Gow6Gng04edFOryHUXH0xhYyRG8PuEv67MfxL UM9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608282; x=1773213082; 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=TwK794DdqJYSdG6zV72tobi0ALWgKSn0ri9Q6Cr47G8=; b=u/+9TlNs8E7B5mpKsyVwGXFBl7yceydE+J+Jjrw/VPSeJ2XnN71H9U94+yldJ+QLCU UmUMacQFKe2PqEV3axZir284PUp/VF/flSFQyxA23K8JQdeBLw6IR2mYUbjImZ5N1URJ VEyECrJWGbbQlYEBPjW/keppv7/yV9lEkWoLhj1B7zqUVar5kCw3+djcfeVSYU4056ag 1F+Z7pQvuRH8+Z0DyyulZ4aEu+f4eFPBJXf2uQzplKyV+Wl/NGKtLrnFRFnyoveOzh4m xx1zAXQT1QuOuiXX43rITXT2XLurTgitqevkNL5immnijid074C1OX0cmZ9+xMaKFoYF z2eA== X-Forwarded-Encrypted: i=1; AJvYcCVU9JzxsDxj1qrIF8bUsIWhZzazV2DlnxDUmpckxyJDIQ/kALscvVH4/ObQl7Do5fYX6utqSl32eugxouM=@vger.kernel.org X-Gm-Message-State: AOJu0YzPl2E7yjJtn21yEzbFk381R/z7CtST1L6JTC1k8/PE+SdDLdLr CeRBiSuzPm0G/rgu5tTGVjodPF8JcqN6Otmy/BU/C3BhITxZ1lX4shyW8e7pAMzehwmeYGqsGWl mKFR3Vw== X-Received: from pjbkk5.prod.google.com ([2002:a17:90b:4a05:b0:359:8cf1:f842]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:248e:b0:359:8988:38d3 with SMTP id 98e67ed59e1d1-359a69aaee9mr712744a91.7.1772608281833; Tue, 03 Mar 2026 23:11:21 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:54 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=3085; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=hrijtfqfOvg8LYhTu0Jxjjl8F1NDkkXHNxjFaW5iGQQ=; b=I5serfzCRE4lgyQ1EMVkv67HSaRK+bPt792Rb5otlWT6cJjSx5JjNfYLAFShLPeiRtzyHXilt s3XXSojIHNlAEwWa4csBB6ACUZB9iztZ3jWwrROQxuSPG2/puNqORdm X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-2-57c9157b58af@google.com> Subject: [PATCH 2/6] Revert "usb: legacy: ncm: Fix NPE in gncm_bind" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , 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 This reverts commit fde0634ad9856b3943a2d1a8cc8de174a63ac840. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/legacy/ncm.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/nc= m.c index e8d565534053..0f1b45e3abd1 100644 --- a/drivers/usb/gadget/legacy/ncm.c +++ b/drivers/usb/gadget/legacy/ncm.c @@ -15,10 +15,8 @@ /* #define DEBUG */ /* #define VERBOSE_DEBUG */ =20 -#include #include #include -#include #include =20 #include "u_ether.h" @@ -131,7 +129,6 @@ static int gncm_bind(struct usb_composite_dev *cdev) struct usb_gadget *gadget =3D cdev->gadget; struct f_ncm_opts *ncm_opts; int status; - u8 mac[ETH_ALEN]; =20 f_ncm_inst =3D usb_get_function_instance("ncm"); if (IS_ERR(f_ncm_inst)) @@ -139,15 +136,11 @@ static int gncm_bind(struct usb_composite_dev *cdev) =20 ncm_opts =3D container_of(f_ncm_inst, struct f_ncm_opts, func_inst); =20 - ncm_opts->net_opts.qmult =3D qmult; - if (host_addr && mac_pton(host_addr, mac)) { - memcpy(&ncm_opts->net_opts.host_mac, mac, ETH_ALEN); + gether_set_qmult(ncm_opts->net, qmult); + if (!gether_set_host_addr(ncm_opts->net, host_addr)) pr_info("using host ethernet address: %s", host_addr); - } - if (dev_addr && mac_pton(dev_addr, mac)) { - memcpy(&ncm_opts->net_opts.dev_mac, mac, ETH_ALEN); + if (!gether_set_dev_addr(ncm_opts->net, dev_addr)) pr_info("using self ethernet address: %s", dev_addr); - } =20 /* Allocate string descriptor numbers ... note that string * contents can be overridden by the composite_dev glue. --=20 2.53.0.473.g4a7958ca14-goog From nobody Wed Apr 15 16:43:55 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 9517936D4E5 for ; Wed, 4 Mar 2026 07:11:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608286; cv=none; b=dh3wq+aAvboG+5QkJZMD7SkO+u+xf0Pm0aVGKKZM1l64ehoHwyPDj52EYT15H7APnovgECCGcYoYW4O7F6+jZxom/9tlafgqco7n5e2rtQFm8mGrCv5C1VAAby66f/YIIQLwIxOri2QKlr7w6LbistPBTfcQwPC1f1kN4i37eQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608286; c=relaxed/simple; bh=vxQAtytnOe9iQTybVOTNQYrvkk5AYCsq3Yn5ZOWsFdM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WwYeaeT4ZBQaxK0TQx9PdBqGxxbodDnWTOgRnTRaAIv/k9Opq3L0Jvnk5oEM38yxKiY9X9Pz6KDECVE326ipxe31GwO6UJN78Nq66mJ4izeAgO71fyFIHUtU/PEZGptgKunPpYXpSzl7agDEsYFlp72k0OzMDTj5IGMu27foqpc= 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=Yhb/UeN9; arc=none smtp.client-ip=209.85.214.201 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="Yhb/UeN9" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ae502a1dd9so39800755ad.3 for ; Tue, 03 Mar 2026 23:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608284; x=1773213084; 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=YtIMjWj8vbky6j7mb7WzKYLLu1mfMyKjlDVfZg0Jd9w=; b=Yhb/UeN9MeKp95BOvn+4T9U7unSU0miuRItofXPeO+4yDuwixNfogVDsBIYojZspc/ GIhWAPX/fTWVoknE0WaTFES7lf3qs+lFnfiYMizn6qgkUO7vhiAJI4nrNOQ5M6qSqTSC dA3RkHtj2ha3LYUUU7WHSznIC4RjA9TlagSt2/8NGeAliipGTwkktsAtlpfBXTWaZf+w +y2ri7MkTF0KxG2Ek0V2GPo1B/dTP2aBMcn1CM1Gfqeo7D0RMc509XMqvgenUruRtDvr a9hEF8YZmkR6OCRzHLdKWXkTZiQ9NkLV5bZP2WVLX0IJhM1tDYGJw0GjnwodfQN+H9a/ pa6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608284; x=1773213084; 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=YtIMjWj8vbky6j7mb7WzKYLLu1mfMyKjlDVfZg0Jd9w=; b=kNJWbaZBL73hv6CaWep12i/1qRP7BykLZfz0mdL+/Jus2DVpkJ1HTxXMGs2ayIo2d/ Su3mlcoIungXZ4LZZoOvqIengQZdqfBqnLjWYc5Vk15ZeSs2wDI7qiShJbe/5EO5mYrQ ZXP8Hgu77DwKnfM2oA/doFBG0BjKNP6YS88s3ANyzFKOQK1UOBXCcWr6v1Mr1/kA27PO OdwCbxM6XBJ0kHIH1UHGv29oI7qN9fIWsF5trUAtXpfmUOSKKa2WAOeJ18EYjY+mRIk3 FAwHtFk1PhtAvDDjS29f3GIluGXnNUeFNRgHS13wD9R15ozZ7TfwMG8V62o7YNomAJ6E Cc3g== X-Forwarded-Encrypted: i=1; AJvYcCWF1qHoK0vBbjhYF588Ha6dfpUtqWZg9vJt7ihMxl9i+Z7NwUU3TwbCZIGY2SXKBvBaLf9IBCClvHgSM50=@vger.kernel.org X-Gm-Message-State: AOJu0YxUFkU+cQZTD4SCXK9KkPCV/FaTUwcEAcfsL+XWKVmjuwU6l9NR 4K1nOwfp2VblWxX9jto4EISiCJ9YExnZbtqpNCd19BoWRGfLeLcWreLn2ZreBMAPICy7dAHokLA IIII8dQ== X-Received: from pjj5.prod.google.com ([2002:a17:90b:5545:b0:359:974a:3d42]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:52c6:b0:359:7b9a:2cf4 with SMTP id 98e67ed59e1d1-359a6899c58mr1257316a91.0.1772608283779; Tue, 03 Mar 2026 23:11:23 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:55 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=11073; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=vxQAtytnOe9iQTybVOTNQYrvkk5AYCsq3Yn5ZOWsFdM=; b=xLet09OHdwUBbUg6/ra2bCJOdB/NmjCeI+v2p4A+Ee7kuN937AzMiZ3Mfj6jZ8N09c/HnW3kg fWKVPnbG2ObBCC2aeMFAkguMaAHW9fnnf6TPaaObm911YPKOJIM7ABX X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-3-57c9157b58af@google.com> Subject: [PATCH 3/6] Revert "usb: gadget: f_ncm: align net_device lifecycle with bind/unbind" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kuen-Han Tsai , stable@kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This reverts commit 56a512a9b4107079f68701e7d55da8507eb963d9. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") Cc: stable@kernel.org Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/function/f_ncm.c | 128 ++++++++++++++++++--------------= ---- drivers/usb/gadget/function/u_ncm.h | 4 +- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/funct= ion/f_ncm.c index 14fc7dce6f39..3d772c9beb91 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -83,11 +83,6 @@ static inline struct f_ncm *func_to_ncm(struct usb_funct= ion *f) return container_of(f, struct f_ncm, port.func); } =20 -static inline struct f_ncm_opts *func_to_ncm_opts(struct usb_function *f) -{ - return container_of(f->fi, struct f_ncm_opts, func_inst); -} - /*------------------------------------------------------------------------= -*/ =20 /* @@ -864,7 +859,6 @@ static int ncm_setup(struct usb_function *f, const stru= ct usb_ctrlrequest *ctrl) static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_ncm *ncm =3D func_to_ncm(f); - struct f_ncm_opts *opts =3D func_to_ncm_opts(f); struct usb_composite_dev *cdev =3D f->config->cdev; =20 /* Control interface has only altsetting 0 */ @@ -887,13 +881,12 @@ static int ncm_set_alt(struct usb_function *f, unsign= ed intf, unsigned alt) if (alt > 1) goto fail; =20 - scoped_guard(mutex, &opts->lock) - if (opts->net) { - DBG(cdev, "reset ncm\n"); - opts->net =3D NULL; - gether_disconnect(&ncm->port); - ncm_reset_values(ncm); - } + if (ncm->netdev) { + DBG(cdev, "reset ncm\n"); + ncm->netdev =3D NULL; + gether_disconnect(&ncm->port); + ncm_reset_values(ncm); + } =20 /* * CDC Network only sends data in non-default altsettings. @@ -926,8 +919,7 @@ static int ncm_set_alt(struct usb_function *f, unsigned= intf, unsigned alt) net =3D gether_connect(&ncm->port); if (IS_ERR(net)) return PTR_ERR(net); - scoped_guard(mutex, &opts->lock) - opts->net =3D net; + ncm->netdev =3D net; } =20 spin_lock(&ncm->lock); @@ -1374,16 +1366,14 @@ static int ncm_unwrap_ntb(struct gether *port, static void ncm_disable(struct usb_function *f) { struct f_ncm *ncm =3D func_to_ncm(f); - struct f_ncm_opts *opts =3D func_to_ncm_opts(f); struct usb_composite_dev *cdev =3D f->config->cdev; =20 DBG(cdev, "ncm deactivated\n"); =20 - scoped_guard(mutex, &opts->lock) - if (opts->net) { - opts->net =3D NULL; - gether_disconnect(&ncm->port); - } + if (ncm->netdev) { + ncm->netdev =3D NULL; + gether_disconnect(&ncm->port); + } =20 if (ncm->notify->enabled) { usb_ep_disable(ncm->notify); @@ -1443,44 +1433,39 @@ static int ncm_bind(struct usb_configuration *c, st= ruct usb_function *f) { struct usb_composite_dev *cdev =3D c->cdev; struct f_ncm *ncm =3D func_to_ncm(f); - struct f_ncm_opts *ncm_opts =3D func_to_ncm_opts(f); struct usb_string *us; int status =3D 0; struct usb_ep *ep; + struct f_ncm_opts *ncm_opts; =20 struct usb_os_desc_table *os_desc_table __free(kfree) =3D NULL; - struct net_device *netdev __free(free_gether_netdev) =3D NULL; struct usb_request *request __free(free_usb_request) =3D NULL; =20 if (!can_support_ecm(cdev->gadget)) return -EINVAL; =20 + ncm_opts =3D container_of(f->fi, struct f_ncm_opts, func_inst); + if (cdev->use_os_string) { os_desc_table =3D kzalloc(sizeof(*os_desc_table), GFP_KERNEL); if (!os_desc_table) return -ENOMEM; } =20 - netdev =3D gether_setup_default(); - if (IS_ERR(netdev)) - return -ENOMEM; - - scoped_guard(mutex, &ncm_opts->lock) { - gether_apply_opts(netdev, &ncm_opts->net_opts); - netdev->mtu =3D ncm_opts->max_segment_size - ETH_HLEN; + mutex_lock(&ncm_opts->lock); + gether_set_gadget(ncm_opts->net, cdev->gadget); + if (!ncm_opts->bound) { + ncm_opts->net->mtu =3D (ncm_opts->max_segment_size - ETH_HLEN); + status =3D gether_register_netdev(ncm_opts->net); } + mutex_unlock(&ncm_opts->lock); =20 - gether_set_gadget(netdev, cdev->gadget); - status =3D gether_register_netdev(netdev); if (status) return status; =20 - /* export host's Ethernet address in CDC format */ - status =3D gether_get_host_addr_cdc(netdev, ncm->ethaddr, - sizeof(ncm->ethaddr)); - if (status < 12) - return -EINVAL; - ncm_string_defs[STRING_MAC_IDX].s =3D ncm->ethaddr; + ncm_opts->bound =3D true; + + ncm_string_defs[1].s =3D ncm->ethaddr; =20 us =3D usb_gstrings_attach(cdev, ncm_strings, ARRAY_SIZE(ncm_string_defs)); @@ -1578,8 +1563,6 @@ static int ncm_bind(struct usb_configuration *c, stru= ct usb_function *f) f->os_desc_n =3D 1; } ncm->notify_req =3D no_free_ptr(request); - ncm->netdev =3D no_free_ptr(netdev); - ncm->port.ioport =3D netdev_priv(ncm->netdev); =20 DBG(cdev, "CDC Network: IN/%s OUT/%s NOTIFY/%s\n", ncm->port.in_ep->name, ncm->port.out_ep->name, @@ -1594,19 +1577,19 @@ static inline struct f_ncm_opts *to_f_ncm_opts(stru= ct config_item *item) } =20 /* f_ncm_item_ops */ -USB_ETHER_OPTS_ITEM(ncm); +USB_ETHERNET_CONFIGFS_ITEM(ncm); =20 /* f_ncm_opts_dev_addr */ -USB_ETHER_OPTS_ATTR_DEV_ADDR(ncm); +USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm); =20 /* f_ncm_opts_host_addr */ -USB_ETHER_OPTS_ATTR_HOST_ADDR(ncm); +USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm); =20 /* f_ncm_opts_qmult */ -USB_ETHER_OPTS_ATTR_QMULT(ncm); +USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm); =20 /* f_ncm_opts_ifname */ -USB_ETHER_OPTS_ATTR_IFNAME(ncm); +USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); =20 static ssize_t ncm_opts_max_segment_size_show(struct config_item *item, char *page) @@ -1672,27 +1655,34 @@ static void ncm_free_inst(struct usb_function_insta= nce *f) struct f_ncm_opts *opts; =20 opts =3D container_of(f, struct f_ncm_opts, func_inst); + if (opts->bound) + gether_cleanup(netdev_priv(opts->net)); + else + free_netdev(opts->net); kfree(opts->ncm_interf_group); kfree(opts); } =20 static struct usb_function_instance *ncm_alloc_inst(void) { - struct usb_function_instance *ret; + struct f_ncm_opts *opts; struct usb_os_desc *descs[1]; char *names[1]; struct config_group *ncm_interf_group; =20 - struct f_ncm_opts *opts __free(kfree) =3D kzalloc_obj(*opts); + opts =3D kzalloc_obj(*opts); if (!opts) return ERR_PTR(-ENOMEM); - - opts->net =3D NULL; opts->ncm_os_desc.ext_compat_id =3D opts->ncm_ext_compat_id; - gether_setup_opts_default(&opts->net_opts, "usb"); =20 mutex_init(&opts->lock); opts->func_inst.free_func_inst =3D ncm_free_inst; + opts->net =3D gether_setup_default(); + if (IS_ERR(opts->net)) { + struct net_device *net =3D opts->net; + kfree(opts); + return ERR_CAST(net); + } opts->max_segment_size =3D ETH_FRAME_LEN; INIT_LIST_HEAD(&opts->ncm_os_desc.ext_prop); =20 @@ -1703,22 +1693,26 @@ static struct usb_function_instance *ncm_alloc_inst= (void) ncm_interf_group =3D usb_os_desc_prepare_interf_dir(&opts->func_inst.group, 1, descs, names, THIS_MODULE); - if (IS_ERR(ncm_interf_group)) + if (IS_ERR(ncm_interf_group)) { + ncm_free_inst(&opts->func_inst); return ERR_CAST(ncm_interf_group); + } opts->ncm_interf_group =3D ncm_interf_group; =20 - ret =3D &opts->func_inst; - retain_and_null_ptr(opts); - return ret; + return &opts->func_inst; } =20 static void ncm_free(struct usb_function *f) { - struct f_ncm_opts *opts =3D func_to_ncm_opts(f); + struct f_ncm *ncm; + struct f_ncm_opts *opts; =20 - scoped_guard(mutex, &opts->lock) - opts->refcnt--; - kfree(func_to_ncm(f)); + ncm =3D func_to_ncm(f); + opts =3D container_of(f->fi, struct f_ncm_opts, func_inst); + kfree(ncm); + mutex_lock(&opts->lock); + opts->refcnt--; + mutex_unlock(&opts->lock); } =20 static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) @@ -1742,15 +1736,13 @@ static void ncm_unbind(struct usb_configuration *c,= struct usb_function *f) =20 kfree(ncm->notify_req->buf); usb_ep_free_request(ncm->notify, ncm->notify_req); - - ncm->port.ioport =3D NULL; - gether_cleanup(netdev_priv(ncm->netdev)); } =20 static struct usb_function *ncm_alloc(struct usb_function_instance *fi) { struct f_ncm *ncm; struct f_ncm_opts *opts; + int status; =20 /* allocate and initialize one new instance */ ncm =3D kzalloc(sizeof(*ncm), GFP_KERNEL); @@ -1758,12 +1750,22 @@ static struct usb_function *ncm_alloc(struct usb_fu= nction_instance *fi) return ERR_PTR(-ENOMEM); =20 opts =3D container_of(fi, struct f_ncm_opts, func_inst); + mutex_lock(&opts->lock); + opts->refcnt++; =20 - scoped_guard(mutex, &opts->lock) - opts->refcnt++; + /* export host's Ethernet address in CDC format */ + status =3D gether_get_host_addr_cdc(opts->net, ncm->ethaddr, + sizeof(ncm->ethaddr)); + if (status < 12) { /* strlen("01234567890a") */ + kfree(ncm); + mutex_unlock(&opts->lock); + return ERR_PTR(-EINVAL); + } =20 spin_lock_init(&ncm->lock); ncm_reset_values(ncm); + ncm->port.ioport =3D netdev_priv(opts->net); + mutex_unlock(&opts->lock); ncm->port.is_fixed =3D true; ncm->port.supports_multi_frame =3D true; =20 diff --git a/drivers/usb/gadget/function/u_ncm.h b/drivers/usb/gadget/funct= ion/u_ncm.h index d99330fe31e8..49ec095cdb4b 100644 --- a/drivers/usb/gadget/function/u_ncm.h +++ b/drivers/usb/gadget/function/u_ncm.h @@ -15,13 +15,11 @@ =20 #include =20 -#include "u_ether.h" - struct f_ncm_opts { struct usb_function_instance func_inst; struct net_device *net; + bool bound; =20 - struct gether_opts net_opts; struct config_group *ncm_interf_group; struct usb_os_desc ncm_os_desc; char ncm_ext_compat_id[16]; --=20 2.53.0.473.g4a7958ca14-goog From nobody Wed Apr 15 16:43:55 2026 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 B0E1C37F74C for ; Wed, 4 Mar 2026 07:11:26 +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=1772608289; cv=none; b=tQbqg7igsBkSxLp68+c5DCVUXCEhtS6L8JL35EKcWFGVgsNWIJq5auLnFAkrXMmwuSZ9jUpySw8K66tw9odZz395QHHuP08MiYpwrAkTp8IKXym6JgJrgmKfn3FTq98iDY/tDxGX5lGGuFh5TwB++exdH0hJ84+PaM1JsGsHJIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608289; c=relaxed/simple; bh=CGO0VfQC6nWNWzuPE6zNy8nqRc46IAy8DWObfpSsHuI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=n+mkC8rONhhsBfOKVswceDm/zQvvH0gdXvpxZw4Q7/1rtfJxHup8ND7EX+xaMMGJdtMNFh3QE1HEJXbOH0wKy61cILoeNPrTNma585NJcSfvex4W7c87rV12WkzY49OH3YdlJps3TaDZE8o6k0qQlAPZ8s4FvB0sYG7EmbJgd4U= 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=cQo5Hacn; 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="cQo5Hacn" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-824ae2c9ff4so17749873b3a.0 for ; Tue, 03 Mar 2026 23:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608286; x=1773213086; 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=QMXsEKlWRclFBEv0xYibqErY/p3FsrhNFarJ+RqhwzI=; b=cQo5Hacnt6ZzNcHOr8W9ZBhh8oDCcUQNYhWRaNTb/HGjIKTg2rOZkkeXUz0cgVMl/h VsCnkeuSof5esSqgqKBJNnC0GioUbsl6SMHJf53QFhF4v7zT2RCnAjQpqGaYsq2vSkPX MluvcskRc6U3CLhqDMv8jbjdAs5Luzsaq62iV39OjBmLDu/rTx4WV4VQBE2Hgm3mcfXZ D8KHAHrT51l6wXKPa2uJ5pnpDR7FUr6yhStj2DigvdB1Sp5sA6M99jEbjCFzpEJV/Q/h vQkGev4mUUGYHGuJQF4MFiPtHa4TSsN6CRmYFk1kSdtSgYCeN9qAUbbhwbldWSSfcJbg uZZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608286; x=1773213086; 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=QMXsEKlWRclFBEv0xYibqErY/p3FsrhNFarJ+RqhwzI=; b=nl0Ukgy7NrGk5THrtXv4PGILaNAHgqmIXa47tKxDUBso9ytoSiIVNG9f9BEo+hBGUr WITO74L2pSmmrZWpoMpq3oejpNXTRWFfF9RKNYKTnbqi/TBpxKnSF5dBIrVakI+k+Ru3 fmIpxS00LDnRcoioNQYTlIwsDXjNrf2fEhrBlBrPNfVcJ6XmB1BpJMZQz1lq9pidVpBh p6+VaD1rD8QaPgEAH8ljg1o26h7cxVt9OacKqbAPW/z6dAWWg/D+cgRUzUBp70GS3wih Oz+aPePGJY041V/qnWxWLbx9V6GzNA2v93IZSD3cbxFqqRkoQjbJPB0xAidU6avnK5De ErHQ== X-Forwarded-Encrypted: i=1; AJvYcCUJwaFywl3rUQCePNnwQwfaEewY9L8XI8xm+lgAxuCHww45nLvZt+9WU73aPb9J3ID5aFdUcJToFSbYcuE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2GZXeQVi27SrZmAcN1AGBtCqNGbbp9bNClWWnbGJfnK7fo1Xc sQF8Ky4bTcSyJvFE+pzF2TL4UDKBbPGTvrS000AifWf6qtj/m/wX0Gbq4x7dOvlJXFuCtP7rI2Y 3koT6XA== X-Received: from pfbeg26.prod.google.com ([2002:a05:6a00:801a:b0:827:1746:d143]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1407:b0:827:4372:dd15 with SMTP id d2e1a72fcca58-82972c6bcf1mr1196817b3a.40.1772608285814; Tue, 03 Mar 2026 23:11:25 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:56 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=3155; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=CGO0VfQC6nWNWzuPE6zNy8nqRc46IAy8DWObfpSsHuI=; b=jO1UL/EGG5ELG8XF3Gtcfb0vrHo+J0K8ptP+j/cvNWgHW/xcPSgC8Hl/GMAHxCoCuYDvQ/EtK xdszOmeBI9mAQbYLlmzCsMa/fZRPhKkoPMJbERjpLLHPenBePCS0ikm X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-4-57c9157b58af@google.com> Subject: [PATCH 4/6] Revert "usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , 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 This reverts commit 0c0981126b99288ed354d3d414c8a5fd42ac9e25. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") 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 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/fun= ction/u_ether.c index 338f6e2a85a9..15685b2f8887 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -1126,21 +1126,6 @@ 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 a212a8ec5eb1..63a0240df4d7 100644 --- a/drivers/usb/gadget/function/u_ether.h +++ b/drivers/usb/gadget/function/u_ether.h @@ -283,8 +283,6 @@ 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.53.0.473.g4a7958ca14-goog From nobody Wed Apr 15 16:43:55 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 78E0337DEBC for ; Wed, 4 Mar 2026 07:11:28 +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=1772608290; cv=none; b=FJhSCXfOkALkwS/ldYp61ER7vHQ+7pOCftMS3ZpkA6a+BdRGaCOzTgu4hPCT/cDVU8+Wgs21oDKci6wf64wGsMj2MhTZdQuAp7d1mSlsTGqPTOP6wZtiv0wI9SqJdz73DB/lofFyTvaWwUaD1AaTKZTyokuewBnexqr4znox8OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608290; c=relaxed/simple; bh=VjRaSPsUVE+x/Xi7XlDdoEy4TQXTYs9VwSowe6Il3dE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XHESoPlTmQEI3rRszcoupNM90CoWn9MurKakLkjBNoLgpjiiraRhp0L/KSY2SnENFUiIGDl/ICVWWiZTxbf5FOc0reUYznCTcyggvGPlD0I4NUraPgLjrOnCE994Mnpqh9cNd5WpLbw4RhrUAbmFtB9jVhWYsv5bDJbNVa/QMcY= 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=meu+fw15; 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="meu+fw15" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-35979a03106so3883571a91.1 for ; Tue, 03 Mar 2026 23:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608288; x=1773213088; 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=ABqRA1fkx2Iasdc5RcVowDEiALyuzvn89TbSr3zsxLo=; b=meu+fw15IOUmVHUtGr/8FJtXmeWeDnXvLHLUNJVrGvhZFR5dQQUtkPIiBurTJDzJr1 IT6t0lBF+BA2Tk626CCAfx8y6/p5T1sxRLch6UT+7q0jT9pTbP3sd6M+XRSaDBvgxcZt 4E8dyiRVbDtN6VEro81UHXdttZD+Wk6icCtmCqgRyJp0iNTp2t/UnXvKAlgcq6/gk6u6 h2qJk/f/8JdLz+o/aEydpIvizMFJwdE8IjTQk2q9EGEMJNcKyqGn/ZIVS59fJQXPEFKz DbBJXVTtR1bMQjulxct4IvxHO958emg6bsHBzBfxhrPiGUF0ZkV4APOsHPQjusL7X79y Wsqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608288; x=1773213088; 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=ABqRA1fkx2Iasdc5RcVowDEiALyuzvn89TbSr3zsxLo=; b=GVEed8Xqaql0BVqNistbkMIPHkVJr0oBJYUokuYXoyVODKVQcYLtxSrMQ8SPnDgUOM RQNDDuyOIkePvlZzbRq6g8Y5XPsV6v9KrJSej/RkMTwWoMfsp3aLqhR90V870fTJ1Rno wsac65bMilWiFpIea2aFPU4vEYgts8gil6ixyZdcQfHQVjtLgVScfNYGOdWdlDd5i1En Y/VlACB2yFra3zxaY9NjyNfbcAUk7jbLvxO7mQgrM0RDz59G5A8YCABnn30mq/VRltGS k2sfMngea5se8/PwXgDIEaGjw2/UvyBYZqYqezPx+aR5CvavlXzUmScar5nKeTTWKBGU uTVg== X-Forwarded-Encrypted: i=1; AJvYcCWQ4PnxRShoPRc3PEcvgE+bIzHEJirR7wGf7xYStIgJhligmwNexCQw9c6dB2cBwvfgFGz0xIni4V9KF1U=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1hAPzzYtT3whgeC7oA6MLOfumtPwk7CVoxUwoxHp3h4QcUkL2 iE1bNg8LewunBMyy215dZ8/KjQJzm7/7pRfB4RU7QsIepdUDfYzHD5HVURhWgIkiGJcqYotP6Yx xrS2rcg== X-Received: from pjbqb9.prod.google.com ([2002:a17:90b:2809:b0:34c:fbee:f264]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c08:b0:34e:63c1:4a08 with SMTP id 98e67ed59e1d1-359a6a3d351mr1043777a91.20.1772608287803; Tue, 03 Mar 2026 23:11:27 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:57 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=2006; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=VjRaSPsUVE+x/Xi7XlDdoEy4TQXTYs9VwSowe6Il3dE=; b=pJZFknIy24tS5KJDQEopYNQRXWsddLGd1VE5BBECEtLIwn1SKJ44tqLj+6ss2j5SPAszQK6T8 SJ+c3gfepyHBP/VtLSU2xfqnWpAEYBoKKKjhOfYs4HaFIZG/+g3uam4 X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-5-57c9157b58af@google.com> Subject: [PATCH 5/6] Revert "usb: gadget: u_ether: use header file" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , 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 This reverts commit 7a7930c0f934fb0c46de6e7ca08e14e11df35dd6. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/function/u_ether_configfs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/g= adget/function/u_ether_configfs.h index 217990a266b2..39d3a261496d 100644 --- a/drivers/usb/gadget/function/u_ether_configfs.h +++ b/drivers/usb/gadget/function/u_ether_configfs.h @@ -14,7 +14,6 @@ #define __U_ETHER_CONFIGFS_H =20 #include -#include #include #include #include --=20 2.53.0.473.g4a7958ca14-goog From nobody Wed Apr 15 16:43:55 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 C497D382289 for ; Wed, 4 Mar 2026 07:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608297; cv=none; b=NcDXVJIElWPVKaeJYhJrThfkY8MoQzNqfANtWgpHzuRY/1DARCDkoibNguZTzim03HEfsj7hYASedtq9bgoa9+kQjgqrWxlBSYAVemnbjni9Y/iUTreVfiwGF5HSAN/ADhV0OcGVVSPm0RVhY266sumksZFaXU7Iz0uTHe+Iilk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772608297; c=relaxed/simple; bh=/m3b4zqGc1iZkhOBcgJHOpbEiI99gvlL58opOGTdGyE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A0Ha15zQTcIDTbZ/gKiEfwBiNohe/vr0sdRUuJr0blgDe3gBixkX+VjS4AcuZvljRYIzpAFeDeD1O/vMmw18wXENWodSyEyDfNdpXyw8Zbg1x3BCSsLGk5SS4EcRHTfbyZR5SB2Saji21NXun9qZjqbTNtTrREASFXVuG9gg+AM= 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=1LEDFH8R; arc=none smtp.client-ip=209.85.215.201 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="1LEDFH8R" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c737b6686ddso235829a12.3 for ; Tue, 03 Mar 2026 23:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772608290; x=1773213090; 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=I/6AkYd5gYPDrKscM6W7dnA+in+IO1rRT3m4qc7cgao=; b=1LEDFH8RONB+8lvf0yRrXsp+tXwH2iJ6PAfR/LO2JNt9d59h8dDd9V4wB1LdJIwbva zLNLiCJgoMI5Qp7AYD+XmSMHpDi4cW0e5ZYPmG5gargRwvSBhC8hvNL56VQd9++R5ai6 5tbrcHyQ5h3pM1vUmtRxTxKEKHt7hW2ZS+C3MPUC48FDKAq/YisC9jNts4zJ0I43h7Fp 9KOtKeeDj4OlZmyWBzq0JD97a66QgDkdk6bH2REs/GvFlWhCOURqbTrKYocBEPUe4dMa 2wDSKEf9bZy6mPYVeYIuTYA/g6z/8cpgTgcnk0YfVDRXmG8n6AmO23zTcxpE7Ep/pWz7 EKvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772608290; x=1773213090; 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=I/6AkYd5gYPDrKscM6W7dnA+in+IO1rRT3m4qc7cgao=; b=rda83loVpuR80nXzUpswTBvwN2ooNYftyW43zpsU0NgGOG9lk5edi+mIBNBW460LA9 8TGM8AFw2vDPQc4F6l9yWDFmTYFip4rUI6th5JlPpx9ZeYNzhZDSDT8vgpLX9gq40ugu XOE8Mpisw63gJNun+o0V+wZsK6Z9kKroD3OkFc6Q4UAaNCtWmo9MRfTZXjBMpHcFOexV LMzr6XUD4PuZwCsgioymrtOiiHDR5FrZBK0+MdTN6ISFfXZYF9ZuGVSCLfIPPzs76T0J vq3SXuWEUiKecM7M0tS9IR/eqAIiDxLfR7XzEj+LXnaGFZ1wnIZkmpfIlvqqUaubOxr3 dQWQ== X-Forwarded-Encrypted: i=1; AJvYcCXBsmQKRC21nCe37wFxWqR3bks8VaJ9Ua1aFY2VuIMO/+oDwmHKKZLjsBvZ+fzq/fUB9kWP49TFNtIyC6g=@vger.kernel.org X-Gm-Message-State: AOJu0YxhOPOAwfq0wNYVxpExZ+JAQRfIzp6pIsa8KOHg8QaWb5LB8krG 4I5nliibcMhMHkIDRupl2pedfjjPoPjG3YO2xc7EQdxpcCP9uDfu55OlH9oxBB+M/XCAsYucSFD WSD9FUw== X-Received: from pgl37.prod.google.com ([2002:a63:b25:0:b0:c66:e983:3013]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:190f:b0:821:8492:7f66 with SMTP id d2e1a72fcca58-82972bbe102mr792491b3a.22.1772608289739; Tue, 03 Mar 2026 23:11:29 -0800 (PST) Date: Wed, 04 Mar 2026 15:10:58 +0800 In-Reply-To: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260304-f-ncm-revert-v1-0-57c9157b58af@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1772608275; l=11207; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=/m3b4zqGc1iZkhOBcgJHOpbEiI99gvlL58opOGTdGyE=; b=sK5kDaydFnRxmdYZwz/7eTqO9/brczTL50kCRboiD0tZznzKYZ/vsOkBqGIWIR3mR9BAnh9Pc xFCWbZJz1X3Dp3L3ziY3wWLJrmjvs/ErKgidfQ3zZYomNO3NYkNs7jm X-Mailer: b4 0.14.3 Message-ID: <20260304-f-ncm-revert-v1-6-57c9157b58af@google.com> Subject: [PATCH 6/6] Revert "usb: gadget: u_ether: add gether_opts for config caching" From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: David Heidelberg , Ernest Van Hoecke , LI Qingwu , 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 This reverts commit e065c6a7e46c2ee9c677fdbf50035323d2de1215. This commit is being reverted as part of a series-wide revert. By deferring the net_device allocation to the bind() phase, a single function instance will spawn multiple network devices if it is symlinked to multiple USB configurations. This causes regressions for userspace tools (like the postmarketOS DHCP daemon) that rely on reading the interface name (e.g., "usb0") from configfs. Currently, configfs returns the template "usb%d", causing the userspace network setup to fail. Crucially, because this patch breaks the 1:1 mapping between the function instance and the network device, this naming issue cannot simply be patched. Configfs only exposes a single 'ifname' attribute per instance, making it impossible to accurately report the actual interface name when multiple underlying network devices can exist for that single instance. All configurations tied to the same function instance are meant to share a single network device. Revert this change to restore the 1:1 mapping by allocating the network device at the instance level (alloc_inst). Reported-by: David Heidelberg Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c95113124= 9af@ixit.cz/ Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with b= ind/unbind") Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/function/u_ether.c | 30 ----- drivers/usb/gadget/function/u_ether.h | 28 ---- drivers/usb/gadget/function/u_ether_configfs.h | 176 ---------------------= ---- 3 files changed, 234 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/fun= ction/u_ether.c index 15685b2f8887..c47965d850d4 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -1040,36 +1040,6 @@ int gether_set_ifname(struct net_device *net, const = char *name, int len) } EXPORT_SYMBOL_GPL(gether_set_ifname); =20 -void gether_setup_opts_default(struct gether_opts *opts, const char *name) -{ - opts->qmult =3D QMULT_DEFAULT; - snprintf(opts->name, sizeof(opts->name), "%s%%d", name); - eth_random_addr(opts->dev_mac); - opts->addr_assign_type =3D NET_ADDR_RANDOM; - eth_random_addr(opts->host_mac); -} -EXPORT_SYMBOL_GPL(gether_setup_opts_default); - -void gether_apply_opts(struct net_device *net, struct gether_opts *opts) -{ - struct eth_dev *dev =3D netdev_priv(net); - - dev->qmult =3D opts->qmult; - - if (opts->ifname_set) { - strscpy(net->name, opts->name, sizeof(net->name)); - dev->ifname_set =3D true; - } - - memcpy(dev->host_mac, opts->host_mac, sizeof(dev->host_mac)); - - if (opts->addr_assign_type =3D=3D NET_ADDR_SET) { - memcpy(dev->dev_mac, opts->dev_mac, sizeof(dev->dev_mac)); - net->addr_assign_type =3D opts->addr_assign_type; - } -} -EXPORT_SYMBOL_GPL(gether_apply_opts); - void gether_suspend(struct gether *link) { struct eth_dev *dev =3D link->ioport; diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/fun= ction/u_ether.h index 63a0240df4d7..34be220cef77 100644 --- a/drivers/usb/gadget/function/u_ether.h +++ b/drivers/usb/gadget/function/u_ether.h @@ -38,31 +38,6 @@ =20 struct eth_dev; =20 -/** - * struct gether_opts - Options for Ethernet gadget function instances - * @name: Pattern for the network interface name (e.g., "usb%d"). - * Used to generate the net device name. - * @qmult: Queue length multiplier for high/super speed. - * @host_mac: The MAC address to be used by the host side. - * @dev_mac: The MAC address to be used by the device side. - * @ifname_set: True if the interface name pattern has been set by userspa= ce. - * @addr_assign_type: The method used for assigning the device MAC address - * (e.g., NET_ADDR_RANDOM, NET_ADDR_SET). - * - * This structure caches network-related settings provided through configfs - * before the net_device is fully instantiated. This allows for early - * configuration while deferring net_device allocation until the function - * is bound. - */ -struct gether_opts { - char name[IFNAMSIZ]; - unsigned int qmult; - u8 host_mac[ETH_ALEN]; - u8 dev_mac[ETH_ALEN]; - bool ifname_set; - unsigned char addr_assign_type; -}; - /* * This represents the USB side of an "ethernet" link, managed by a USB * function which provides control and (maybe) framing. Two functions @@ -284,9 +259,6 @@ int gether_set_ifname(struct net_device *net, const cha= r *name, int len); =20 void gether_cleanup(struct eth_dev *dev); =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); - void gether_suspend(struct gether *link); void gether_resume(struct gether *link); =20 diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/g= adget/function/u_ether_configfs.h index 39d3a261496d..51f0d79e5eca 100644 --- a/drivers/usb/gadget/function/u_ether_configfs.h +++ b/drivers/usb/gadget/function/u_ether_configfs.h @@ -13,12 +13,6 @@ #ifndef __U_ETHER_CONFIGFS_H #define __U_ETHER_CONFIGFS_H =20 -#include -#include -#include -#include -#include - #define USB_ETHERNET_CONFIGFS_ITEM(_f_) \ static void _f_##_attr_release(struct config_item *item) \ { \ @@ -203,174 +197,4 @@ out: \ \ CONFIGFS_ATTR(_f_##_opts_, _n_) =20 -#define USB_ETHER_OPTS_ITEM(_f_) \ - static void _f_##_attr_release(struct config_item *item) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - \ - usb_put_function_instance(&opts->func_inst); \ - } \ - \ - static struct configfs_item_operations _f_##_item_ops =3D { \ - .release =3D _f_##_attr_release, \ - } - -#define USB_ETHER_OPTS_ATTR_DEV_ADDR(_f_) \ - static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \ - char *page) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - \ - guard(mutex)(&opts->lock); \ - return sysfs_emit(page, "%pM\n", opts->net_opts.dev_mac); \ - } \ - \ - static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \ - const char *page, size_t len) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - u8 new_addr[ETH_ALEN]; \ - const char *p =3D page; \ - \ - guard(mutex)(&opts->lock); \ - if (opts->refcnt) \ - return -EBUSY; \ - \ - for (int i =3D 0; i < ETH_ALEN; i++) { \ - unsigned char num; \ - if ((*p =3D=3D '.') || (*p =3D=3D ':')) \ - p++; \ - num =3D hex_to_bin(*p++) << 4; \ - num |=3D hex_to_bin(*p++); \ - new_addr[i] =3D num; \ - } \ - if (!is_valid_ether_addr(new_addr)) \ - return -EINVAL; \ - memcpy(opts->net_opts.dev_mac, new_addr, ETH_ALEN); \ - opts->net_opts.addr_assign_type =3D NET_ADDR_SET; \ - return len; \ - } \ - \ - CONFIGFS_ATTR(_f_##_opts_, dev_addr) - -#define USB_ETHER_OPTS_ATTR_HOST_ADDR(_f_) \ - static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \ - char *page) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - \ - guard(mutex)(&opts->lock); \ - return sysfs_emit(page, "%pM\n", opts->net_opts.host_mac); \ - } \ - \ - static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \ - const char *page, size_t len) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - u8 new_addr[ETH_ALEN]; \ - const char *p =3D page; \ - \ - guard(mutex)(&opts->lock); \ - if (opts->refcnt) \ - return -EBUSY; \ - \ - for (int i =3D 0; i < ETH_ALEN; i++) { \ - unsigned char num; \ - if ((*p =3D=3D '.') || (*p =3D=3D ':')) \ - p++; \ - num =3D hex_to_bin(*p++) << 4; \ - num |=3D hex_to_bin(*p++); \ - new_addr[i] =3D num; \ - } \ - if (!is_valid_ether_addr(new_addr)) \ - return -EINVAL; \ - memcpy(opts->net_opts.host_mac, new_addr, ETH_ALEN); \ - return len; \ - } \ - \ - CONFIGFS_ATTR(_f_##_opts_, host_addr) - -#define USB_ETHER_OPTS_ATTR_QMULT(_f_) \ - static ssize_t _f_##_opts_qmult_show(struct config_item *item, \ - char *page) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - \ - guard(mutex)(&opts->lock); \ - return sysfs_emit(page, "%u\n", opts->net_opts.qmult); \ - } \ - \ - static ssize_t _f_##_opts_qmult_store(struct config_item *item, \ - const char *page, size_t len) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - u32 val; \ - int ret; \ - \ - guard(mutex)(&opts->lock); \ - if (opts->refcnt) \ - return -EBUSY; \ - \ - ret =3D kstrtou32(page, 0, &val); \ - if (ret) \ - return ret; \ - \ - opts->net_opts.qmult =3D val; \ - return len; \ - } \ - \ - CONFIGFS_ATTR(_f_##_opts_, qmult) - -#define USB_ETHER_OPTS_ATTR_IFNAME(_f_) \ - static ssize_t _f_##_opts_ifname_show(struct config_item *item, \ - char *page) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - const char *name; \ - \ - guard(mutex)(&opts->lock); \ - rtnl_lock(); \ - if (opts->net_opts.ifname_set) \ - name =3D opts->net_opts.name; \ - else if (opts->net) \ - name =3D netdev_name(opts->net); \ - else \ - name =3D "(inactive net_device)"; \ - rtnl_unlock(); \ - return sysfs_emit(page, "%s\n", name); \ - } \ - \ - static ssize_t _f_##_opts_ifname_store(struct config_item *item, \ - const char *page, size_t len) \ - { \ - struct f_##_f_##_opts *opts =3D to_f_##_f_##_opts(item); \ - char tmp[IFNAMSIZ]; \ - const char *p; \ - size_t c_len =3D len; \ - \ - if (c_len > 0 && page[c_len - 1] =3D=3D '\n') \ - c_len--; \ - \ - if (c_len >=3D sizeof(tmp)) \ - return -E2BIG; \ - \ - strscpy(tmp, page, c_len + 1); \ - if (!dev_valid_name(tmp)) \ - return -EINVAL; \ - \ - /* Require exactly one %d */ \ - p =3D strchr(tmp, '%'); \ - if (!p || p[1] !=3D 'd' || strchr(p + 2, '%')) \ - return -EINVAL; \ - \ - guard(mutex)(&opts->lock); \ - if (opts->refcnt) \ - return -EBUSY; \ - strscpy(opts->net_opts.name, tmp, sizeof(opts->net_opts.name)); \ - opts->net_opts.ifname_set =3D true; \ - return len; \ - } \ - \ - CONFIGFS_ATTR(_f_##_opts_, ifname) - #endif /* __U_ETHER_CONFIGFS_H */ --=20 2.53.0.473.g4a7958ca14-goog