Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "usb: gadget: f_ncm: Fix atomic context locking issue"

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 <david@ixit.cz>
Closes: https://lore.kernel.org/linux-usb/70b558ea-a12e-4170-9b8e-c951131249af@ixit.cz/
Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with bind/unbind")
Cc: stable <stable@kernel.org>
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Link: https://patch.msgid.link/20260309-f-ncm-revert-v2-1-ea2afbc7d9b2@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kuen-Han Tsai and committed by
Greg Kroah-Hartman
11199720 e8557acf

+28 -13
+17 -12
drivers/usb/gadget/function/f_ncm.c
··· 58 58 u8 notify_state; 59 59 atomic_t notify_count; 60 60 bool is_open; 61 - bool is_connected; 62 61 63 62 const struct ndp_parser_opts *parser_opts; 64 63 bool is_crc; ··· 864 865 static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 865 866 { 866 867 struct f_ncm *ncm = func_to_ncm(f); 868 + struct f_ncm_opts *opts = func_to_ncm_opts(f); 867 869 struct usb_composite_dev *cdev = f->config->cdev; 868 870 869 871 /* Control interface has only altsetting 0 */ ··· 887 887 if (alt > 1) 888 888 goto fail; 889 889 890 - if (ncm->is_connected) { 891 - DBG(cdev, "reset ncm\n"); 892 - ncm->is_connected = false; 893 - gether_disconnect(&ncm->port); 894 - ncm_reset_values(ncm); 895 - } 890 + scoped_guard(mutex, &opts->lock) 891 + if (opts->net) { 892 + DBG(cdev, "reset ncm\n"); 893 + opts->net = NULL; 894 + gether_disconnect(&ncm->port); 895 + ncm_reset_values(ncm); 896 + } 896 897 897 898 /* 898 899 * CDC Network only sends data in non-default altsettings. ··· 926 925 net = gether_connect(&ncm->port); 927 926 if (IS_ERR(net)) 928 927 return PTR_ERR(net); 929 - ncm->is_connected = true; 928 + scoped_guard(mutex, &opts->lock) 929 + opts->net = net; 930 930 } 931 931 932 932 spin_lock(&ncm->lock); ··· 1374 1372 static void ncm_disable(struct usb_function *f) 1375 1373 { 1376 1374 struct f_ncm *ncm = func_to_ncm(f); 1375 + struct f_ncm_opts *opts = func_to_ncm_opts(f); 1377 1376 struct usb_composite_dev *cdev = f->config->cdev; 1378 1377 1379 1378 DBG(cdev, "ncm deactivated\n"); 1380 1379 1381 - if (ncm->is_connected) { 1382 - ncm->is_connected = false; 1383 - gether_disconnect(&ncm->port); 1384 - } 1380 + scoped_guard(mutex, &opts->lock) 1381 + if (opts->net) { 1382 + opts->net = NULL; 1383 + gether_disconnect(&ncm->port); 1384 + } 1385 1385 1386 1386 if (ncm->notify->enabled) { 1387 1387 usb_ep_disable(ncm->notify); ··· 1687 1683 if (!opts) 1688 1684 return ERR_PTR(-ENOMEM); 1689 1685 1686 + opts->net = NULL; 1690 1687 opts->ncm_os_desc.ext_compat_id = opts->ncm_ext_compat_id; 1691 1688 gether_setup_opts_default(&opts->net_opts, "usb"); 1692 1689
+10 -1
drivers/usb/gadget/function/u_ether_configfs.h
··· 327 327 char *page) \ 328 328 { \ 329 329 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 330 + const char *name; \ 330 331 \ 331 332 guard(mutex)(&opts->lock); \ 332 - return sysfs_emit(page, "%s\n", opts->net_opts.name); \ 333 + rtnl_lock(); \ 334 + if (opts->net_opts.ifname_set) \ 335 + name = opts->net_opts.name; \ 336 + else if (opts->net) \ 337 + name = netdev_name(opts->net); \ 338 + else \ 339 + name = "(inactive net_device)"; \ 340 + rtnl_unlock(); \ 341 + return sysfs_emit(page, "%s\n", name); \ 333 342 } \ 334 343 \ 335 344 static ssize_t _f_##_opts_ifname_store(struct config_item *item, \
+1
drivers/usb/gadget/function/u_ncm.h
··· 19 19 20 20 struct f_ncm_opts { 21 21 struct usb_function_instance func_inst; 22 + struct net_device *net; 22 23 23 24 struct gether_opts net_opts; 24 25 struct config_group *ncm_interf_group;