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: legacy: ncm: Fix NPE in gncm_bind"

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 <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-2-ea2afbc7d9b2@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

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

+3 -10
+3 -10
drivers/usb/gadget/legacy/ncm.c
··· 15 15 /* #define DEBUG */ 16 16 /* #define VERBOSE_DEBUG */ 17 17 18 - #include <linux/hex.h> 19 18 #include <linux/kernel.h> 20 19 #include <linux/module.h> 21 - #include <linux/string.h> 22 20 #include <linux/usb/composite.h> 23 21 24 22 #include "u_ether.h" ··· 129 131 struct usb_gadget *gadget = cdev->gadget; 130 132 struct f_ncm_opts *ncm_opts; 131 133 int status; 132 - u8 mac[ETH_ALEN]; 133 134 134 135 f_ncm_inst = usb_get_function_instance("ncm"); 135 136 if (IS_ERR(f_ncm_inst)) ··· 136 139 137 140 ncm_opts = container_of(f_ncm_inst, struct f_ncm_opts, func_inst); 138 141 139 - ncm_opts->net_opts.qmult = qmult; 140 - if (host_addr && mac_pton(host_addr, mac)) { 141 - memcpy(&ncm_opts->net_opts.host_mac, mac, ETH_ALEN); 142 + gether_set_qmult(ncm_opts->net, qmult); 143 + if (!gether_set_host_addr(ncm_opts->net, host_addr)) 142 144 pr_info("using host ethernet address: %s", host_addr); 143 - } 144 - if (dev_addr && mac_pton(dev_addr, mac)) { 145 - memcpy(&ncm_opts->net_opts.dev_mac, mac, ETH_ALEN); 145 + if (!gether_set_dev_addr(ncm_opts->net, dev_addr)) 146 146 pr_info("using self ethernet address: %s", dev_addr); 147 - } 148 147 149 148 /* Allocate string descriptor numbers ... note that string 150 149 * contents can be overridden by the composite_dev glue.