Skip to content

Commit 1d15e6a

Browse files
committed
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: aac7b10 ("Allow mac address to be set in smsc95xx") Signed-off-by: Philipp Rosenberger <[email protected]> [lukas: fix netif_dbg() indentation as well, wordsmith commit message] Signed-off-by: Lukas Wunner <[email protected]> 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 <[email protected]> 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 <[email protected]> [lukas: leave 2nd function parameter unchanged, wordsmith commit message] Signed-off-by: Lukas Wunner <[email protected]>
1 parent 6f4106f commit 1d15e6a

File tree

1 file changed

+17
-44
lines changed

1 file changed

+17
-44
lines changed

drivers/net/usb/smsc95xx.c

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -812,49 +812,18 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
812812
}
813813

814814
/* Check the macaddr module parameter for a MAC address */
815-
static int smsc95xx_is_macaddr_param(struct usbnet *dev, struct net_device *nd)
815+
static int smsc95xx_macaddr_param(struct usbnet *dev, struct net_device *nd)
816816
{
817-
int i, j, got_num, num;
818-
u8 mtbl[ETH_ALEN];
819-
820-
if (macaddr[0] == ':')
821-
return 0;
822-
823-
i = 0;
824-
j = 0;
825-
num = 0;
826-
got_num = 0;
827-
while (j < ETH_ALEN) {
828-
if (macaddr[i] && macaddr[i] != ':') {
829-
got_num++;
830-
if ('0' <= macaddr[i] && macaddr[i] <= '9')
831-
num = num * 16 + macaddr[i] - '0';
832-
else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
833-
num = num * 16 + 10 + macaddr[i] - 'A';
834-
else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
835-
num = num * 16 + 10 + macaddr[i] - 'a';
836-
else
837-
break;
838-
i++;
839-
} else if (got_num == 2) {
840-
mtbl[j++] = (u8) num;
841-
num = 0;
842-
got_num = 0;
843-
i++;
844-
} else {
845-
break;
846-
}
847-
}
848-
849-
if (j == ETH_ALEN) {
850-
netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
851-
"%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
852-
mtbl[3], mtbl[4], mtbl[5]);
853-
dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
854-
return 1;
855-
} else {
856-
return 0;
857-
}
817+
u8 mtbl[ETH_ALEN];
818+
819+
if (mac_pton(macaddr, mtbl)) {
820+
netif_dbg(dev, ifup, dev->net,
821+
"Overriding MAC address with: %pM\n", mtbl);
822+
dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
823+
return 0;
824+
} else {
825+
return -EINVAL;
826+
}
858827
}
859828

860829
static void smsc95xx_init_mac_address(struct usbnet *dev)
@@ -881,8 +850,12 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
881850
}
882851

883852
/* Check module parameters */
884-
if (smsc95xx_is_macaddr_param(dev, dev->net))
885-
return;
853+
if (smsc95xx_macaddr_param(dev, dev->net) == 0) {
854+
if (is_valid_ether_addr(dev->net->dev_addr)) {
855+
netif_dbg(dev, ifup, dev->net, "MAC address read from module parameter\n");
856+
return;
857+
}
858+
}
886859

887860
/* no useful static MAC address found. generate a random one */
888861
eth_hw_addr_random(dev->net);

0 commit comments

Comments
 (0)