summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch')
-rw-r--r--target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch120
1 files changed, 120 insertions, 0 deletions
diff --git a/target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch b/target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch
new file mode 100644
index 0000000000..9265e931fa
--- /dev/null
+++ b/target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch
@@ -0,0 +1,120 @@
+From 1d15e6a34222cc8d8eb1050e7a3e276b0348be41 Mon Sep 17 00:00:00 2001
+From: Phil Elwell <phil@raspberrypi.com>
+Date: Mon, 3 Jul 2023 11:04:56 +0100
+Subject: [PATCH] fixup! Allow mac address to be set in smsc95xx
+
+usbnet: smsc95xx: Fix indentation of smsc95xx_is_macaddr_param()
+
+smsc95xx_is_macaddr_param() is incorrectly indented, it uses 7 spaces
+instead of tabs. Fix it.
+
+Fixes: aac7b105788e ("Allow mac address to be set in smsc95xx")
+Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
+[lukas: fix netif_dbg() indentation as well, wordsmith commit message]
+Signed-off-by: Lukas Wunner <lukas@wunner.de>
+
+usbnet: smsc95xx: Simplify MAC address parsing
+
+Parsing the MAC address provided on the kernel command line can be
+simplified quite a bit by taking advantage of the kernel's built-in
+mac_pton() helper.
+
+Likewise emitting the MAC address can be simplified with the %pM
+format string conversion.
+
+Signed-off-by: Lukas Wunner <lukas@wunner.de>
+
+usbnet: smsc95xx: Fix style issues in smsc95xx_is_macaddr_param()
+
+It is bad practice to have a function named ..._is_...() which has side
+effects. So drop the 'is' from the name.
+
+Per kernel convention return 0 on success and a negative errno on
+failure.
+
+Validate the MAC address retrieved from the command line.
+
+Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
+[lukas: leave 2nd function parameter unchanged, wordsmith commit message]
+Signed-off-by: Lukas Wunner <lukas@wunner.de>
+---
+ drivers/net/usb/smsc95xx.c | 61 +++++++++++---------------------------
+ 1 file changed, 17 insertions(+), 44 deletions(-)
+
+--- a/drivers/net/usb/smsc95xx.c
++++ b/drivers/net/usb/smsc95xx.c
+@@ -814,49 +814,18 @@ static int smsc95xx_ioctl(struct net_dev
+ }
+
+ /* Check the macaddr module parameter for a MAC address */
+-static int smsc95xx_is_macaddr_param(struct usbnet *dev, struct net_device *nd)
++static int smsc95xx_macaddr_param(struct usbnet *dev, struct net_device *nd)
+ {
+- int i, j, got_num, num;
+- u8 mtbl[ETH_ALEN];
++ u8 mtbl[ETH_ALEN];
+
+- if (macaddr[0] == ':')
+- return 0;
+-
+- i = 0;
+- j = 0;
+- num = 0;
+- got_num = 0;
+- while (j < ETH_ALEN) {
+- if (macaddr[i] && macaddr[i] != ':') {
+- got_num++;
+- if ('0' <= macaddr[i] && macaddr[i] <= '9')
+- num = num * 16 + macaddr[i] - '0';
+- else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
+- num = num * 16 + 10 + macaddr[i] - 'A';
+- else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
+- num = num * 16 + 10 + macaddr[i] - 'a';
+- else
+- break;
+- i++;
+- } else if (got_num == 2) {
+- mtbl[j++] = (u8) num;
+- num = 0;
+- got_num = 0;
+- i++;
+- } else {
+- break;
+- }
+- }
+-
+- if (j == ETH_ALEN) {
+- netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
+- "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
+- mtbl[3], mtbl[4], mtbl[5]);
+- dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
+- return 1;
+- } else {
+- return 0;
+- }
++ if (mac_pton(macaddr, mtbl)) {
++ netif_dbg(dev, ifup, dev->net,
++ "Overriding MAC address with: %pM\n", mtbl);
++ dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
++ return 0;
++ } else {
++ return -EINVAL;
++ }
+ }
+
+ static void smsc95xx_init_mac_address(struct usbnet *dev)
+@@ -883,8 +852,12 @@ static void smsc95xx_init_mac_address(st
+ }
+
+ /* Check module parameters */
+- if (smsc95xx_is_macaddr_param(dev, dev->net))
+- return;
++ if (smsc95xx_macaddr_param(dev, dev->net) == 0) {
++ if (is_valid_ether_addr(dev->net->dev_addr)) {
++ netif_dbg(dev, ifup, dev->net, "MAC address read from module parameter\n");
++ return;
++ }
++ }
+
+ /* no useful static MAC address found. generate a random one */
+ eth_hw_addr_random(dev->net);