Skip to content

Commit 51c5d2b

Browse files
committed
Allow mac address to be set in smsc95xx
Signed-off-by: popcornmix <[email protected]> SQUASH: smsc95xx: Use dev_mod_addr to set MAC addr Since adeef3e ("net: constify netdev->dev_addr") it has been illegal to write to the dev_addr MAC address field. Later commits have added explicit checks that it hasn't been modified by nefarious means. The dev_addr_mod helper function is the accepted way to change the dev_addr field, so use it. Squash with 96c1def ("Allow mac address to be set in smsc95xx"). Signed-off-by: Phil Elwell <[email protected]>
1 parent 79e4c38 commit 51c5d2b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/net/usb/smsc95xx.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ static int packetsize = 2560;
8383
module_param(packetsize, int, 0644);
8484
MODULE_PARM_DESC(packetsize, "Override the RX URB packet size");
8585

86+
static char *macaddr = ":";
87+
module_param(macaddr, charp, 0);
88+
MODULE_PARM_DESC(macaddr, "MAC address");
89+
8690
static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
8791
u32 *data)
8892
{
@@ -805,6 +809,21 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
805809
return phy_mii_ioctl(netdev->phydev, rq, cmd);
806810
}
807811

812+
/* Check the macaddr module parameter for a MAC address */
813+
static int smsc95xx_macaddr_param(struct usbnet *dev, struct net_device *nd)
814+
{
815+
u8 mtbl[ETH_ALEN];
816+
817+
if (mac_pton(macaddr, mtbl)) {
818+
netif_dbg(dev, ifup, dev->net,
819+
"Overriding MAC address with: %pM\n", mtbl);
820+
dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
821+
return 0;
822+
} else {
823+
return -EINVAL;
824+
}
825+
}
826+
808827
static void smsc95xx_init_mac_address(struct usbnet *dev)
809828
{
810829
u8 addr[ETH_ALEN];
@@ -828,6 +847,14 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
828847
}
829848
}
830849

850+
/* Check module parameters */
851+
if (smsc95xx_macaddr_param(dev, dev->net) == 0) {
852+
if (is_valid_ether_addr(dev->net->dev_addr)) {
853+
netif_dbg(dev, ifup, dev->net, "MAC address read from module parameter\n");
854+
return;
855+
}
856+
}
857+
831858
/* no useful static MAC address found. generate a random one */
832859
eth_hw_addr_random(dev->net);
833860
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");

0 commit comments

Comments
 (0)