summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch
blob: 9265e931facce89dc951eb1c099be8be6a15354f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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);