Message ID | 20220817171043.459267-1-saproj@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: moxa: MAC address reading, generating, validity checking | expand |
> @@ -539,6 +533,11 @@ static int moxart_mac_probe(struct platform_device *pdev) > > SET_NETDEV_DEV(ndev, &pdev->dev); > > + ret = platform_get_ethdev_address(p_dev, ndev); > + if (ret) > + eth_hw_addr_random(ndev); You should look at the return value. It could be EPROBE_DEFFER, because the EEPROM has not probed yet. You need to return this value, so that the device core will probe other devices, including the EEPROM, and then later reprobe this driver. Andrew
diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index f11f1cb92025..7b11efe629a5 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -62,9 +62,6 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr) { struct sockaddr *address = addr; - if (!is_valid_ether_addr(address->sa_data)) - return -EADDRNOTAVAIL; - eth_hw_addr_set(ndev, address->sa_data); moxart_update_mac_address(ndev); @@ -172,9 +169,6 @@ static int moxart_mac_open(struct net_device *ndev) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); - if (!is_valid_ether_addr(ndev->dev_addr)) - return -EADDRNOTAVAIL; - napi_enable(&priv->napi); moxart_mac_reset(ndev); @@ -539,6 +533,11 @@ static int moxart_mac_probe(struct platform_device *pdev) SET_NETDEV_DEV(ndev, &pdev->dev); + ret = platform_get_ethdev_address(p_dev, ndev); + if (ret) + eth_hw_addr_random(ndev); + moxart_update_mac_address(ndev); + ret = register_netdev(ndev); if (ret) goto init_fail;
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 Signed-off-by: Sergei Antonov <saproj@gmail.com> Suggested-by: Andrew Lunn <andrew@lunn.ch> CC: Jakub Kicinski <kuba@kernel.org> CC: Vladimir Oltean <olteanv@gmail.com> CC: Yang Yingliang <yangyingliang@huawei.com> CC: Pavel Skripkin <paskripkin@gmail.com> CC: Yang Wei <yang.wei9@zte.com.cn> CC: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- drivers/net/ethernet/moxa/moxart_ether.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)