Skip to content

Commit f4693b8

Browse files
saprojkuba-moo
authored andcommitted
net: moxa: MAC address reading, generating, validity checking
This device does not remember its MAC address, so add a possibility to get it from the platform. If it fails, generate a random address. This will provide a MAC address early during boot without user space being involved. Also remove extra calls to is_valid_ether_addr(). Made after suggestions by Andrew Lunn: 1) Use eth_hw_addr_random() to assign a random MAC address during probe. 2) Remove is_valid_ether_addr() from moxart_mac_open() 3) Add a call to platform_get_ethdev_address() during probe 4) Remove is_valid_ether_addr() from moxart_set_mac_address(). The core does this v1 -> v2: Handle EPROBE_DEFER returned from platform_get_ethdev_address(). Move MAC reading code to the beginning of the probe function. Signed-off-by: Sergei Antonov <[email protected]> Suggested-by: Andrew Lunn <[email protected]> CC: Yang Yingliang <[email protected]> CC: Pavel Skripkin <[email protected]> CC: Guobin Huang <[email protected]> CC: Yang Wei <[email protected]> CC: Christophe JAILLET <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 267ef48 commit f4693b8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/net/ethernet/moxa/moxart_ether.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr)
6262
{
6363
struct sockaddr *address = addr;
6464

65-
if (!is_valid_ether_addr(address->sa_data))
66-
return -EADDRNOTAVAIL;
67-
6865
eth_hw_addr_set(ndev, address->sa_data);
6966
moxart_update_mac_address(ndev);
7067

@@ -172,9 +169,6 @@ static int moxart_mac_open(struct net_device *ndev)
172169
{
173170
struct moxart_mac_priv_t *priv = netdev_priv(ndev);
174171

175-
if (!is_valid_ether_addr(ndev->dev_addr))
176-
return -EADDRNOTAVAIL;
177-
178172
napi_enable(&priv->napi);
179173

180174
moxart_mac_reset(ndev);
@@ -488,6 +482,13 @@ static int moxart_mac_probe(struct platform_device *pdev)
488482
}
489483
ndev->base_addr = res->start;
490484

485+
ret = platform_get_ethdev_address(p_dev, ndev);
486+
if (ret == -EPROBE_DEFER)
487+
goto init_fail;
488+
if (ret)
489+
eth_hw_addr_random(ndev);
490+
moxart_update_mac_address(ndev);
491+
491492
spin_lock_init(&priv->txlock);
492493

493494
priv->tx_buf_size = TX_BUF_SIZE;

0 commit comments

Comments
 (0)