Skip to content

Commit bab8eb0

Browse files
oneukumkuba-moo
authored andcommitted
usbnet: modern method to get random MAC
The driver generates a random MAC once on load and uses it over and over, including on two devices needing a random MAC at the same time. Jakub suggested revamping the driver to the modern API for setting a random MAC rather than fixing the old stuff. The bug is as old as the driver. Signed-off-by: Oliver Neukum <oneukum@suse.com> Reviewed-by: Simon Horman <horms@kernel.org> Fixes: 1da177e ("Linux-2.6.12-rc2") Link: https://patch.msgid.link/20240829175201.670718-1-oneukum@suse.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent cfd433c commit bab8eb0

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/net/usb/usbnet.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161

6262
/*-------------------------------------------------------------------------*/
6363

64-
// randomly generated ethernet address
65-
static u8 node_id [ETH_ALEN];
66-
6764
/* use ethtool to change the level for any given device */
6865
static int msg_level = -1;
6966
module_param (msg_level, int, 0);
@@ -1725,7 +1722,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
17251722

17261723
dev->net = net;
17271724
strscpy(net->name, "usb%d", sizeof(net->name));
1728-
eth_hw_addr_set(net, node_id);
17291725

17301726
/* rx and tx sides can use different message sizes;
17311727
* bind() should set rx_urb_size in that case.
@@ -1801,9 +1797,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
18011797
goto out4;
18021798
}
18031799

1804-
/* let userspace know we have a random address */
1805-
if (ether_addr_equal(net->dev_addr, node_id))
1806-
net->addr_assign_type = NET_ADDR_RANDOM;
1800+
/* this flags the device for user space */
1801+
if (!is_valid_ether_addr(net->dev_addr))
1802+
eth_hw_addr_random(net);
18071803

18081804
if ((dev->driver_info->flags & FLAG_WLAN) != 0)
18091805
SET_NETDEV_DEVTYPE(net, &wlan_type);
@@ -2211,7 +2207,6 @@ static int __init usbnet_init(void)
22112207
BUILD_BUG_ON(
22122208
sizeof_field(struct sk_buff, cb) < sizeof(struct skb_data));
22132209

2214-
eth_random_addr(node_id);
22152210
return 0;
22162211
}
22172212
module_init(usbnet_init);

0 commit comments

Comments
 (0)