linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: thunder_bgx: use OF loop instead of fwnode
@ 2025-08-30 21:42 Rosen Penev
  2025-09-01 15:23 ` Simon Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2025-08-30 21:42 UTC (permalink / raw)
  To: netdev
  Cc: Sunil Goutham, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni,
	moderated list:ARM/CAVIUM THUNDER NETWORK DRIVER, open list

The loop ends up converting fwnode to device_node anyway.

While at it, handle return value of of_get_mac_address in case of NVMEM.

Simplify while loop iteration.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 .../net/ethernet/cavium/thunder/thunder_bgx.c | 27 ++++++++-----------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 21495b5dce25..eb5525c1482e 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1468,27 +1468,23 @@ static int bgx_init_acpi_phy(struct bgx *bgx)
 
 static int bgx_init_of_phy(struct bgx *bgx)
 {
-	struct fwnode_handle *fwn;
-	struct device_node *node = NULL;
+	struct device_node *node = bgx->pdev->dev.of_node;
+	struct device_node *child;
 	u8 lmac = 0;
 
-	device_for_each_child_node(&bgx->pdev->dev, fwn) {
+	for_each_child_of_node(node, child) {
 		struct phy_device *pd;
 		struct device_node *phy_np;
+		int err;
 
-		/* Should always be an OF node.  But if it is not, we
-		 * cannot handle it, so exit the loop.
-		 */
-		node = to_of_node(fwn);
-		if (!node)
-			break;
-
-		of_get_mac_address(node, bgx->lmac[lmac].mac);
+		err = of_get_mac_address(child, bgx->lmac[lmac].mac);
+		if (err == -EPROBE_DEFER)
+			goto defer;
 
 		SET_NETDEV_DEV(bgx->lmac[lmac].netdev, &bgx->pdev->dev);
 		bgx->lmac[lmac].lmacid = lmac;
 
-		phy_np = of_parse_phandle(node, "phy-handle", 0);
+		phy_np = of_parse_phandle(child, "phy-handle", 0);
 		/* If there is no phy or defective firmware presents
 		 * this cortina phy, for which there is no driver
 		 * support, ignore it.
@@ -1504,7 +1500,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
 
 		lmac++;
 		if (lmac == bgx->max_lmac) {
-			of_node_put(node);
+			of_node_put(child);
 			break;
 		}
 	}
@@ -1514,14 +1510,13 @@ static int bgx_init_of_phy(struct bgx *bgx)
 	/* We are bailing out, try not to leak device reference counts
 	 * for phy devices we may have already found.
 	 */
-	while (lmac) {
+	while (lmac--) {
 		if (bgx->lmac[lmac].phydev) {
 			put_device(&bgx->lmac[lmac].phydev->mdio.dev);
 			bgx->lmac[lmac].phydev = NULL;
 		}
-		lmac--;
 	}
-	of_node_put(node);
+	of_node_put(child);
 	return -EPROBE_DEFER;
 }
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: thunder_bgx: use OF loop instead of fwnode
  2025-08-30 21:42 [PATCH] net: thunder_bgx: use OF loop instead of fwnode Rosen Penev
@ 2025-09-01 15:23 ` Simon Horman
  2025-09-01 21:23   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2025-09-01 15:23 UTC (permalink / raw)
  To: Rosen Penev
  Cc: netdev, Sunil Goutham, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni,
	moderated list:ARM/CAVIUM THUNDER NETWORK DRIVER, open list

On Sat, Aug 30, 2025 at 02:42:17PM -0700, Rosen Penev wrote:
> The loop ends up converting fwnode to device_node anyway.
> 
> While at it, handle return value of of_get_mac_address in case of NVMEM.

I think that this part should be a separate patch.
Possibly targeted at net with a Fixes tag.

> 
> Simplify while loop iteration.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

...

> @@ -1514,14 +1510,13 @@ static int bgx_init_of_phy(struct bgx *bgx)
>  	/* We are bailing out, try not to leak device reference counts
>  	 * for phy devices we may have already found.
>  	 */
> -	while (lmac) {
> +	while (lmac--) {
>  		if (bgx->lmac[lmac].phydev) {
>  			put_device(&bgx->lmac[lmac].phydev->mdio.dev);
>  			bgx->lmac[lmac].phydev = NULL;
>  		}
> -		lmac--;
>  	}

The update to this look looks correct to me, even without the rest of
the patch separate. If so, I'm wondering if it should also be a separate
patch. Again, possibly for net with a Fixes tag.

> -	of_node_put(node);
> +	of_node_put(child);
>  	return -EPROBE_DEFER;
>  }

...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: thunder_bgx: use OF loop instead of fwnode
  2025-09-01 15:23 ` Simon Horman
@ 2025-09-01 21:23   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2025-09-01 21:23 UTC (permalink / raw)
  To: Simon Horman
  Cc: netdev, Sunil Goutham, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni,
	moderated list:ARM/CAVIUM THUNDER NETWORK DRIVER, open list

On Mon, Sep 1, 2025 at 8:23 AM Simon Horman <horms@kernel.org> wrote:
>
> On Sat, Aug 30, 2025 at 02:42:17PM -0700, Rosen Penev wrote:
> > The loop ends up converting fwnode to device_node anyway.
> >
> > While at it, handle return value of of_get_mac_address in case of NVMEM.
>
> I think that this part should be a separate patch.
> Possibly targeted at net with a Fixes tag.
I'll split up.
>
> >
> > Simplify while loop iteration.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> ...
>
> > @@ -1514,14 +1510,13 @@ static int bgx_init_of_phy(struct bgx *bgx)
> >       /* We are bailing out, try not to leak device reference counts
> >        * for phy devices we may have already found.
> >        */
> > -     while (lmac) {
> > +     while (lmac--) {
> >               if (bgx->lmac[lmac].phydev) {
> >                       put_device(&bgx->lmac[lmac].phydev->mdio.dev);
> >                       bgx->lmac[lmac].phydev = NULL;
> >               }
> > -             lmac--;
> >       }
>
> The update to this look looks correct to me, even without the rest of
> the patch separate. If so, I'm wondering if it should also be a separate
> patch. Again, possibly for net with a Fixes tag.
Maybe not. This can get called while lmac is 0, which is a u8. lmac--
like this will underflow. I'll send it as a separate patch from the
upcoming series targeted at next.
>
> > -     of_node_put(node);
> > +     of_node_put(child);
> >       return -EPROBE_DEFER;
> >  }
>
> ...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-01 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-30 21:42 [PATCH] net: thunder_bgx: use OF loop instead of fwnode Rosen Penev
2025-09-01 15:23 ` Simon Horman
2025-09-01 21:23   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).