From nobody Thu Apr 9 12:50:36 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 C421B3A6404 for ; Mon, 9 Mar 2026 12:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773057922; cv=none; b=Plv6bu3FKIW/CzxDxccBCGBpj6YuicBS6Blyz2khsAVFvirgtyCvy026p0cORt7rHheoJItSD3A16g4RBV4tEn07y9GpnoyzkRKHb/RONudjiCAWkk5P6QvYPBS1KY174IJCkOUufU8vWUItYxlwkOBCoh4gcKn9T00olAOYPsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773057922; c=relaxed/simple; bh=5/YxhynNP5OtTJz20C93GRmdTUgl+LzpEZyjUYK3nk0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ndRfUk/DQvqir6DsG4oHudZmHLfNllUaSPrSoaNgXw3kZ2EMr+M+kwxR8S/ToS6TNZoNgUdBOvKHc12vdyilZLHheUvrgUtIL4tmtFYuMfRjxwyJHMMGmEDgAcH2VflVFXFrJp3F0ob0KEQpAK50Jiro1L5G9iKqLjpQqgvqOVY= 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=EPep4LD9; arc=none smtp.client-ip=209.85.214.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="EPep4LD9" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ae49080364so66391695ad.0 for ; Mon, 09 Mar 2026 05:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773057918; x=1773662718; 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=EPep4LD9GhZSsD3Q8MOWfGAIpU3WV8tkKqdylJ2Cd57Mgto1hLrbfHtPav2X7m0o/N oT+KNtaYMSP5O/ki9FdPBSRm/3+CBDZKdmzy/wQHN7X/QLNVDlpeOVfak+lUB38+tsuh iVWv2CtJdqsp76ynMHKMcUUP9mIplM3Ws565TbPFQO1rzLiCmjuQ/TbHeMCs5cTCeeN2 54hI4DmylCfQ8SB/cBOGaIJAxXvbRNFyZd/fGG3lc16yH9e3hEahvo81TfGkFrxhU066 v4SUhXUcXtClGEDx4f7O7tNl94D42Dm6tXnrZHCOWNic8kmCrbwjNGMncF3uUMT1twBU z6iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773057918; x=1773662718; 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=ddYsVGPXGlcTrMDMFm7wmWLTWVY0dQqhNDIxRdnUeDP+6FMPrn/nXmtBbSp1H6qeqn cIpWseuKlBmQqQ/+HtzVmlVSEK1x2NzVCbGfLeF2Wqu5Mm2wVvpqQLEzw5Pegb04hy6Z rGA56KiD8JLXdjb9XHi7keN2PRC46LzlLLGC8BjGTWwVH51GnWA9xX2vfo4NR5pMircd 5rWplONRUUpgYQhOp/mV1/ZKvui4vtHsDnXgg+dBzFNYJo1YDzTEtLqzdkK5j4qN9gr+ Ez3QKSF68BXVgks7JIFF8SNXbmizwqqqKJGz2XenumU/mt96UBpaxV+CsAdf9VqgtDlg WUxQ== X-Forwarded-Encrypted: i=1; AJvYcCVcqfZmn0FVb9aEuw4KMI8lM+W1TAOWT+LEMWLkQI7GrU9KMPTjbwBvLaHYuNfPAv3Al1EBEr3+R/5nLkw=@vger.kernel.org X-Gm-Message-State: AOJu0YzmaCnFwNOIUaxXMyjWxotS/hXaiphJ3qEyWg2HyiiGsiQIohol +yd+x/Fda6PB5vESVMy+xV6rZb5w3Jul0bWd8BCztdk+HwsLuE1yckDEs29ndWktgEjl6i2BCyS fS9l3tg== X-Received: from plbmi14.prod.google.com ([2002:a17:902:fcce:b0:2ae:8189:6d82]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:f87:b0:2ae:44f4:1678 with SMTP id d9443c01a7336-2ae824b83e7mr102046305ad.57.1773057917958; Mon, 09 Mar 2026 05:05:17 -0700 (PDT) Date: Mon, 09 Mar 2026 20:04:46 +0800 In-Reply-To: <20260309-f-ncm-revert-v2-0-ea2afbc7d9b2@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260309-f-ncm-revert-v2-0-ea2afbc7d9b2@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1773057914; l=5610; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=5/YxhynNP5OtTJz20C93GRmdTUgl+LzpEZyjUYK3nk0=; b=x/I92mmzRMq+qRpeXxxEasVw5ga1d/zxTzpfK55lfaMSKWuCUqkBCVOhOqywT8qiyfBDrtl4E F1m+KinqSkaCYgpIQUtHQQnlG1GXqwuQt2ZK/eqT8VE9RK6tm2jMhez X-Mailer: b4 0.14.3 Message-ID: <20260309-f-ncm-revert-v2-1-ea2afbc7d9b2@google.com> Subject: [PATCH v2 1/7] Revert "usb: gadget: f_ncm: Fix atomic context locking issue" From: Kuen-Han Tsai To: Greg Kroah-Hartman , Felipe Balbi , Kyungmin Park Cc: David Heidelberg , Ernest Van Hoecke , Jon Hunter , 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