bcm27xx: update 6.1 patches to latest version
[openwrt/staging/dangole.git] / target / linux / bcm27xx / patches-6.1 / 950-0804-fixup-Allow-mac-address-to-be-set-in-smsc95xx.patch
1 From 1d15e6a34222cc8d8eb1050e7a3e276b0348be41 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Mon, 3 Jul 2023 11:04:56 +0100
4 Subject: [PATCH] fixup! Allow mac address to be set in smsc95xx
5
6 usbnet: smsc95xx: Fix indentation of smsc95xx_is_macaddr_param()
7
8 smsc95xx_is_macaddr_param() is incorrectly indented, it uses 7 spaces
9 instead of tabs. Fix it.
10
11 Fixes: aac7b105788e ("Allow mac address to be set in smsc95xx")
12 Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
13 [lukas: fix netif_dbg() indentation as well, wordsmith commit message]
14 Signed-off-by: Lukas Wunner <lukas@wunner.de>
15
16 usbnet: smsc95xx: Simplify MAC address parsing
17
18 Parsing the MAC address provided on the kernel command line can be
19 simplified quite a bit by taking advantage of the kernel's built-in
20 mac_pton() helper.
21
22 Likewise emitting the MAC address can be simplified with the %pM
23 format string conversion.
24
25 Signed-off-by: Lukas Wunner <lukas@wunner.de>
26
27 usbnet: smsc95xx: Fix style issues in smsc95xx_is_macaddr_param()
28
29 It is bad practice to have a function named ..._is_...() which has side
30 effects. So drop the 'is' from the name.
31
32 Per kernel convention return 0 on success and a negative errno on
33 failure.
34
35 Validate the MAC address retrieved from the command line.
36
37 Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
38 [lukas: leave 2nd function parameter unchanged, wordsmith commit message]
39 Signed-off-by: Lukas Wunner <lukas@wunner.de>
40 ---
41 drivers/net/usb/smsc95xx.c | 61 +++++++++++---------------------------
42 1 file changed, 17 insertions(+), 44 deletions(-)
43
44 --- a/drivers/net/usb/smsc95xx.c
45 +++ b/drivers/net/usb/smsc95xx.c
46 @@ -814,49 +814,18 @@ static int smsc95xx_ioctl(struct net_dev
47 }
48
49 /* Check the macaddr module parameter for a MAC address */
50 -static int smsc95xx_is_macaddr_param(struct usbnet *dev, struct net_device *nd)
51 +static int smsc95xx_macaddr_param(struct usbnet *dev, struct net_device *nd)
52 {
53 - int i, j, got_num, num;
54 - u8 mtbl[ETH_ALEN];
55 + u8 mtbl[ETH_ALEN];
56
57 - if (macaddr[0] == ':')
58 - return 0;
59 -
60 - i = 0;
61 - j = 0;
62 - num = 0;
63 - got_num = 0;
64 - while (j < ETH_ALEN) {
65 - if (macaddr[i] && macaddr[i] != ':') {
66 - got_num++;
67 - if ('0' <= macaddr[i] && macaddr[i] <= '9')
68 - num = num * 16 + macaddr[i] - '0';
69 - else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
70 - num = num * 16 + 10 + macaddr[i] - 'A';
71 - else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
72 - num = num * 16 + 10 + macaddr[i] - 'a';
73 - else
74 - break;
75 - i++;
76 - } else if (got_num == 2) {
77 - mtbl[j++] = (u8) num;
78 - num = 0;
79 - got_num = 0;
80 - i++;
81 - } else {
82 - break;
83 - }
84 - }
85 -
86 - if (j == ETH_ALEN) {
87 - netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
88 - "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
89 - mtbl[3], mtbl[4], mtbl[5]);
90 - dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
91 - return 1;
92 - } else {
93 - return 0;
94 - }
95 + if (mac_pton(macaddr, mtbl)) {
96 + netif_dbg(dev, ifup, dev->net,
97 + "Overriding MAC address with: %pM\n", mtbl);
98 + dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
99 + return 0;
100 + } else {
101 + return -EINVAL;
102 + }
103 }
104
105 static void smsc95xx_init_mac_address(struct usbnet *dev)
106 @@ -883,8 +852,12 @@ static void smsc95xx_init_mac_address(st
107 }
108
109 /* Check module parameters */
110 - if (smsc95xx_is_macaddr_param(dev, dev->net))
111 - return;
112 + if (smsc95xx_macaddr_param(dev, dev->net) == 0) {
113 + if (is_valid_ether_addr(dev->net->dev_addr)) {
114 + netif_dbg(dev, ifup, dev->net, "MAC address read from module parameter\n");
115 + return;
116 + }
117 + }
118
119 /* no useful static MAC address found. generate a random one */
120 eth_hw_addr_random(dev->net);