]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: f_ncm: Fix MAC assignment NCM ethernet
authorraub camaioni <raubcameo@gmail.com>
Fri, 15 Aug 2025 13:07:21 +0000 (09:07 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Dec 2025 11:45:09 +0000 (12:45 +0100)
[ Upstream commit 956606bafb5fc6e5968aadcda86fc0037e1d7548 ]

This fix is already present in f_ecm.c and was never
propagated to f_ncm.c

When creating multiple NCM ethernet devices
on a composite usb gadget device
each MAC address on the HOST side will be identical.
Having the same MAC on different network interfaces is bad.

This fix updates the MAC address inside the
ncm_strings_defs global during the ncm_bind call.
This ensures each device has a unique MAC.
In f_ecm.c ecm_string_defs is updated in the same way.

The defunct MAC assignment in ncm_alloc has been removed.

Signed-off-by: raub camaioni <raubcameo@gmail.com>
Link: https://lore.kernel.org/r/20250815131358.1047525-1-raubcameo@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/gadget/function/f_ncm.c

index ca50257b95384d56dbdb5e7931230e9edf8f7c61..b1e5693373820256c552f72387c7e2a1593893a7 100644 (file)
@@ -1472,6 +1472,8 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f)
 
        ncm_opts->bound = true;
 
+       ncm_string_defs[1].s = ncm->ethaddr;
+
        us = usb_gstrings_attach(cdev, ncm_strings,
                                 ARRAY_SIZE(ncm_string_defs));
        if (IS_ERR(us)) {
@@ -1735,7 +1737,6 @@ static struct usb_function *ncm_alloc(struct usb_function_instance *fi)
                mutex_unlock(&opts->lock);
                return ERR_PTR(-EINVAL);
        }
-       ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr;
 
        spin_lock_init(&ncm->lock);
        ncm_reset_values(ncm);