Skip to contentSkip to conversation

net: bcmasp: handle EPROBE_DEFER for MAC retrieval

PATCH Superseded Rosen Penev 3 participants 4 messages Apr 28 – Apr 29

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

PATCH v2 1/1 net: bcmasp: handle EPROBE_DEFER for MAC retrieval

of_get_ethdev_address can return EPROBE_DEFER when using nvmem. To handle this, encode the error with ERR_PTR for minimal changes. Adjust the only place using bcmasp_interface_create.

---
v2: use dev_err_probe.

 drivers/net/ethernet/broadcom/asp2/bcmasp.c      | 6 +++---
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 ++++--
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -3
index 972474893a6b..e9b11b956344 100644
@@ -1333,10 +1333,10 @@ static int bcmasp_probe(struct platform_device *pdev)
 	i = 0;
 	for_each_available_child_of_node_scoped(ports_node, intf_node) {
 		intf = bcmasp_interface_create(priv, intf_node, i);
-		if (!intf) {
-			dev_err(dev, "Cannot create eth interface %d\n", i);
+		if (IS_ERR(intf)) {
 			of_node_put(ports_node);
-			ret = -EINVAL;
+			ret = dev_err_probe(dev, PTR_ERR(intf), "Cannot create eth interface %d\n",
+					    i);
 			goto err_cleanup;
 		}
 		list_add_tail(&intf->list, &priv->intfs);
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +4 -2
index ec63f50a849e..caf0e408e2f7 100644
@@ -1254,7 +1254,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
 	struct device *dev = &priv->pdev->dev;
 	struct bcmasp_intf *intf;
 	struct net_device *ndev;
-	int ch, port, ret;
+	int ch, port, ret = -EINVAL;
 
 	if (of_property_read_u32(ndev_dn, "reg", &port)) {
 		dev_warn(dev, "%s: invalid port number\n", ndev_dn->name);
@@ -1314,6 +1314,8 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
 	}
 
 	ret = of_get_ethdev_address(ndev_dn, ndev);
+	if (ret == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);
 	if (ret) {
 		netdev_warn(ndev, "using random Ethernet MAC\n");
 		eth_hw_addr_random(ndev);
@@ -1340,7 +1342,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
 err_free_netdev:
 	free_netdev(ndev);
 err:
-	return NULL;
+	return ERR_PTR(ret);
 }
 
 void bcmasp_interface_destroy(struct bcmasp_intf *intf)
Signature · 1 line
2.54.0
#1 lore raw

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, · line 1257

Quoted 7 lines

+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -1
@@ -1254,7 +1254,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
 	struct device *dev = &priv->pdev->dev;
 	struct bcmasp_intf *intf;
 	struct net_device *ndev;
-	int ch, port, ret;
+	int ch, port, ret = -EINVAL;

That breaks the reverse christmas tree. Otherwise this looks O.K.

Andrew

---
pw-bot: cr

maintainer
#2 lore raw
In reply to Rosen Penev
Quoted 43 lines · Rosen Penev

of_get_ethdev_address can return EPROBE_DEFER when using nvmem. To handle this, encode the error with ERR_PTR for minimal changes. Adjust the only place using bcmasp_interface_create.

---
v2: use dev_err_probe.

  drivers/net/ethernet/broadcom/asp2/bcmasp.c      | 6 +++---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 ++++--
  2 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -3
index 972474893a6b..e9b11b956344 100644
@@ -1333,10 +1333,10 @@ static int bcmasp_probe(struct platform_device *pdev)
  	i = 0;
  	for_each_available_child_of_node_scoped(ports_node, intf_node) {
  		intf = bcmasp_interface_create(priv, intf_node, i);
-		if (!intf) {
-			dev_err(dev, "Cannot create eth interface %d\n", i);
+		if (IS_ERR(intf)) {
  			of_node_put(ports_node);
-			ret = -EINVAL;
+			ret = dev_err_probe(dev, PTR_ERR(intf), "Cannot create eth interface %d\n",
+					    i);
  			goto err_cleanup;
  		}
  		list_add_tail(&intf->list, &priv->intfs);
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -1
index ec63f50a849e..caf0e408e2f7 100644
@@ -1254,7 +1254,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
  	struct device *dev = &priv->pdev->dev;
  	struct bcmasp_intf *intf;
  	struct net_device *ndev;
-	int ch, port, ret;
+	int ch, port, ret = -EINVAL;
 
  	if (of_property_read_u32(ndev_dn, "reg", &port)) {
  		dev_warn(dev, "%s: invalid port number\n", ndev_dn->name);

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, · line 1318

Quoted 5 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +2 -0
@@ -1314,6 +1314,8 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
  	}
 
  	ret = of_get_ethdev_address(ndev_dn, ndev);
+	if (ret == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);

Do we need to hit unwind here? i.e. goto err_deregister_fixed_link.

Thanks,
Justin

Quoted 12 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -1
  	if (ret) {
  		netdev_warn(ndev, "using random Ethernet MAC\n");
  		eth_hw_addr_random(ndev);
@@ -1340,7 +1342,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
  err_free_netdev:
  	free_netdev(ndev);
  err:
-	return NULL;
+	return ERR_PTR(ret);
  }
 
  void bcmasp_interface_destroy(struct bcmasp_intf *intf)
#3 lore raw
Quoted 49 lines · Justin Chen
Quoted 45 lines · Rosen Penev

of_get_ethdev_address can return EPROBE_DEFER when using nvmem. To handle this, encode the error with ERR_PTR for minimal changes. Adjust the only place using bcmasp_interface_create.

---
v2: use dev_err_probe.

  drivers/net/ethernet/broadcom/asp2/bcmasp.c      | 6 +++---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 ++++--
  2 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -3
index 972474893a6b..e9b11b956344 100644
@@ -1333,10 +1333,10 @@ static int bcmasp_probe(struct platform_device *pdev)
      i = 0;
      for_each_available_child_of_node_scoped(ports_node, intf_node) {
              intf = bcmasp_interface_create(priv, intf_node, i);
-             if (!intf) {
-                     dev_err(dev, "Cannot create eth interface %d\n", i);
+             if (IS_ERR(intf)) {
                      of_node_put(ports_node);
-                     ret = -EINVAL;
+                     ret = dev_err_probe(dev, PTR_ERR(intf), "Cannot create eth interface %d\n",
+                                         i);
                      goto err_cleanup;
              }
              list_add_tail(&intf->list, &priv->intfs);
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -1
index ec63f50a849e..caf0e408e2f7 100644
@@ -1254,7 +1254,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
      struct device *dev = &priv->pdev->dev;
      struct bcmasp_intf *intf;
      struct net_device *ndev;
-     int ch, port, ret;
+     int ch, port, ret = -EINVAL;
 
      if (of_property_read_u32(ndev_dn, "reg", &port)) {
              dev_warn(dev, "%s: invalid port number\n", ndev_dn->name);
@@ -1314,6 +1314,8 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
      }
 
Quoted 5 lines

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, · line 1318

Quoted 3 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +2 -0
      ret = of_get_ethdev_address(ndev_dn, ndev);
+     if (ret == -EPROBE_DEFER)
+             return ERR_PTR(-EPROBE_DEFER);

Do we need to hit unwind here? i.e. goto err_deregister_fixed_link.

Yes we do. In other news I just sent another v2 by accident. Guess I'll wait to send a v4...

Quoted 17 lines

Thanks,
Justin

Quoted 12 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -1
      if (ret) {
              netdev_warn(ndev, "using random Ethernet MAC\n");
              eth_hw_addr_random(ndev);
@@ -1340,7 +1342,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
  err_free_netdev:
      free_netdev(ndev);
  err:
-     return NULL;
+     return ERR_PTR(ret);
  }
 
  void bcmasp_interface_destroy(struct bcmasp_intf *intf)