Skip to content

Commit f2524c0

Browse files
Kuen-Han Tsaigregkh
authored andcommitted
Revert "usb: legacy: ncm: Fix NPE in gncm_bind"
This reverts commit fde0634. 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: 56a512a ("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>
1 parent 1119972 commit f2524c0

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

  • drivers/usb/gadget/legacy

drivers/usb/gadget/legacy/ncm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
/* #define DEBUG */
1616
/* #define VERBOSE_DEBUG */
1717

18-
#include <linux/hex.h>
1918
#include <linux/kernel.h>
2019
#include <linux/module.h>
21-
#include <linux/string.h>
2220
#include <linux/usb/composite.h>
2321

2422
#include "u_ether.h"
@@ -131,23 +129,18 @@ static int gncm_bind(struct usb_composite_dev *cdev)
131129
struct usb_gadget *gadget = cdev->gadget;
132130
struct f_ncm_opts *ncm_opts;
133131
int status;
134-
u8 mac[ETH_ALEN];
135132

136133
f_ncm_inst = usb_get_function_instance("ncm");
137134
if (IS_ERR(f_ncm_inst))
138135
return PTR_ERR(f_ncm_inst);
139136

140137
ncm_opts = container_of(f_ncm_inst, struct f_ncm_opts, func_inst);
141138

142-
ncm_opts->net_opts.qmult = qmult;
143-
if (host_addr && mac_pton(host_addr, mac)) {
144-
memcpy(&ncm_opts->net_opts.host_mac, mac, ETH_ALEN);
139+
gether_set_qmult(ncm_opts->net, qmult);
140+
if (!gether_set_host_addr(ncm_opts->net, host_addr))
145141
pr_info("using host ethernet address: %s", host_addr);
146-
}
147-
if (dev_addr && mac_pton(dev_addr, mac)) {
148-
memcpy(&ncm_opts->net_opts.dev_mac, mac, ETH_ALEN);
142+
if (!gether_set_dev_addr(ncm_opts->net, dev_addr))
149143
pr_info("using self ethernet address: %s", dev_addr);
150-
}
151144

152145
/* Allocate string descriptor numbers ... note that string
153146
* contents can be overridden by the composite_dev glue.

0 commit comments

Comments
 (0)