Skip to contentSkip to conversation

net: bcmgenet: Generate a random MAC if none is valid

PATCH Applied Florian Fainelli 5 participants 6 messages Oct 14, 2019 – Oct 16, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: bcmgenet: Generate a random MAC if none is valid

Instead of having a hard failure and stopping the driver's probe routine, generate a random Ethernet MAC address to keep going.

---
Changes in v2:

- provide a message that a random MAC is used, the same message that bcmsysport.c uses

 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +8 -9
index 12cb77ef1081..dd4e4f1dd384 100644
@@ -3461,16 +3461,10 @@ static int bcmgenet_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	if (dn) {
+	if (dn)
 		macaddr = of_get_mac_address(dn);
-		if (IS_ERR(macaddr)) {
-			dev_err(&pdev->dev, "can't find MAC address\n");
-			err = -EINVAL;
-			goto err;
-		}
-	} else {
+	else
 		macaddr = pd->mac_address;
-	}
 
 	priv->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->base)) {
@@ -3482,7 +3476,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
 
 	SET_NETDEV_DEV(dev, &pdev->dev);
 	dev_set_drvdata(&pdev->dev, dev);
-	ether_addr_copy(dev->dev_addr, macaddr);
+	if (IS_ERR_OR_NULL(macaddr) || !is_valid_ether_addr(macaddr)) {
+		dev_warn(&pdev->dev, "using random Ethernet MAC\n");
+		eth_hw_addr_random(dev);
+	} else {
+		ether_addr_copy(dev->dev_addr, macaddr);
+	}
 	dev->watchdog_timeo = 2 * HZ;
 	dev->ethtool_ops = &bcmgenet_ethtool_ops;
 	dev->netdev_ops = &bcmgenet_netdev_ops;
Signature · 1 line
2.17.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 41 lines · Florian Fainelli

Instead of having a hard failure and stopping the driver's probe routine, generate a random Ethernet MAC address to keep going.

---
Changes in v2:

- provide a message that a random MAC is used, the same message that bcmsysport.c uses

 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -8
index 12cb77ef1081..dd4e4f1dd384 100644
@@ -3461,16 +3461,10 @@ static int bcmgenet_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	if (dn) {
+	if (dn)
 		macaddr = of_get_mac_address(dn);
-		if (IS_ERR(macaddr)) {
-			dev_err(&pdev->dev, "can't find MAC address\n");
-			err = -EINVAL;
-			goto err;
-		}
-	} else {
+	else
 		macaddr = pd->mac_address;
-	}
 
 	priv->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->base)) {
@@ -3482,7 +3476,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
 
 	SET_NETDEV_DEV(dev, &pdev->dev);
 	dev_set_drvdata(&pdev->dev, dev);

drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 3487

Quoted 10 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -1
-	ether_addr_copy(dev->dev_addr, macaddr);
+	if (IS_ERR_OR_NULL(macaddr) || !is_valid_ether_addr(macaddr)) {
+		dev_warn(&pdev->dev, "using random Ethernet MAC\n");
+		eth_hw_addr_random(dev);
+	} else {
+		ether_addr_copy(dev->dev_addr, macaddr);
+	}
 	dev->watchdog_timeo = 2 * HZ;
 	dev->ethtool_ops = &bcmgenet_ethtool_ops;
 	dev->netdev_ops = &bcmgenet_netdev_ops;
#2 lore raw
In reply to Florian Fainelli

Hi Florian,

Quoted 37 lines · Florian Fainelli

Instead of having a hard failure and stopping the driver's probe routine, generate a random Ethernet MAC address to keep going.

---
Changes in v2:

- provide a message that a random MAC is used, the same message that bcmsysport.c uses

  drivers/net/ethernet/broadcom/genet/bcmgenet.c | 17 ++++++++---------
  1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -8
index 12cb77ef1081..dd4e4f1dd384 100644
@@ -3461,16 +3461,10 @@ static int bcmgenet_probe(struct platform_device *pdev)
  		goto err;
  	}
 
-	if (dn) {
+	if (dn)
  		macaddr = of_get_mac_address(dn);
-		if (IS_ERR(macaddr)) {
-			dev_err(&pdev->dev, "can't find MAC address\n");
-			err = -EINVAL;
-			goto err;
-		}
-	} else {
+	else
  		macaddr = pd->mac_address;
-	}
 
  	priv->base = devm_platform_ioremap_resource(pdev, 0);
  	if (IS_ERR(priv->base)) {

drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 3480

Quoted 6 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -1
@@ -3482,7 +3476,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
 
  	SET_NETDEV_DEV(dev, &pdev->dev);
  	dev_set_drvdata(&pdev->dev, dev);
-	ether_addr_copy(dev->dev_addr, macaddr);
+	if (IS_ERR_OR_NULL(macaddr) || !is_valid_ether_addr(macaddr)) {
+		dev_warn(&pdev->dev, "using random Ethernet MAC\n");

I would still consider this warrants a dev_err as you should not be using the device with a random MAC address assigned to it.  But I'll leave it to the "experts" to decide on the print level here.

Quoted 7 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +4 -0
+		eth_hw_addr_random(dev);
+	} else {
+		ether_addr_copy(dev->dev_addr, macaddr);
+	}
  	dev->watchdog_timeo = 2 * HZ;
  	dev->ethtool_ops = &bcmgenet_ethtool_ops;
  	dev->netdev_ops = &bcmgenet_netdev_ops;
#3 lore raw
Quoted 11 lines · Scott Branden

drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 3480

Quoted 7 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -1
@@ -3482,7 +3476,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
 
  	SET_NETDEV_DEV(dev, &pdev->dev);
  	dev_set_drvdata(&pdev->dev, dev);
-	ether_addr_copy(dev->dev_addr, macaddr);
+	if (IS_ERR_OR_NULL(macaddr) || !is_valid_ether_addr(macaddr)) {
+		dev_warn(&pdev->dev, "using random Ethernet MAC\n");  

I would still consider this warrants a dev_err as you should not be using the device with a random MAC address assigned to it.  But I'll leave it to the "experts" to decide on the print level here.

FWIW I'd stick to warn for this message since this is no longer a hard failure.

maintainer
#4 lore raw

From: Jakub Kicinski <[email protected]>
Date: Tue, 15 Oct 2019 15:39:55 -0700

Quoted 13 lines · Scott Branden
Quoted 11 lines

drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 3480

Quoted 7 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -1
@@ -3482,7 +3476,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
 
  	SET_NETDEV_DEV(dev, &pdev->dev);
  	dev_set_drvdata(&pdev->dev, dev);
-	ether_addr_copy(dev->dev_addr, macaddr);
+	if (IS_ERR_OR_NULL(macaddr) || !is_valid_ether_addr(macaddr)) {
+		dev_warn(&pdev->dev, "using random Ethernet MAC\n");  

I would still consider this warrants a dev_err as you should not be using the device with a random MAC address assigned to it.  But I'll leave it to the "experts" to decide on the print level here.

Quoted 2 lines

FWIW I'd stick to warn for this message since this is no longer a hard failure.

Agreed.