diff mbox series

[net-next] net: renesas: rswitch: Convert to for_each_available_child_of_node()

Message ID 54f544d573a64b96e01fd00d3481b10806f4d110.1738771798.git.geert+renesas@glider.be (mailing list archive)
State Under Review
Delegated to: Geert Uytterhoeven
Headers show
Series [net-next] net: renesas: rswitch: Convert to for_each_available_child_of_node() | expand

Commit Message

Geert Uytterhoeven Feb. 5, 2025, 4:12 p.m. UTC
Simplify rswitch_get_port_node() by using the
for_each_available_child_of_node() helper instead of manually ignoring
unavailable child nodes, and leaking a reference.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Tested on R-Car S4 Starter Kit, which has port 2 disabled.
---
 drivers/net/ethernet/renesas/rswitch.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Nikita Yushchenko Feb. 5, 2025, 4:15 p.m. UTC | #1
Hello Geert.

> Simplify rswitch_get_port_node() by using the
> for_each_available_child_of_node() helper instead of manually ignoring
> unavailable child nodes, and leaking a reference.

FYI, I have a patch in my queue that replaces this code with traversing child nodes (via 
for_each_available_child_of_node()) and only creating devices for ports actually defined in the device tree.

Nikita
Geert Uytterhoeven Feb. 5, 2025, 4:18 p.m. UTC | #2
Hi Nikita,

On Wed, 5 Feb 2025 at 17:15, Nikita Yushchenko
<nikita.yoush@cogentembedded.com> wrote:
> > Simplify rswitch_get_port_node() by using the
> > for_each_available_child_of_node() helper instead of manually ignoring
> > unavailable child nodes, and leaking a reference.
>
> FYI, I have a patch in my queue that replaces this code with traversing child nodes (via
> for_each_available_child_of_node()) and only creating devices for ports actually defined in the device tree.

OK, thanks for letting me know!

Gr{oetje,eeting}s,

                        Geert
Simon Horman Feb. 6, 2025, 4:31 p.m. UTC | #3
On Wed, Feb 05, 2025 at 05:18:14PM +0100, Geert Uytterhoeven wrote:
> Hi Nikita,
> 
> On Wed, 5 Feb 2025 at 17:15, Nikita Yushchenko
> <nikita.yoush@cogentembedded.com> wrote:
> > > Simplify rswitch_get_port_node() by using the
> > > for_each_available_child_of_node() helper instead of manually ignoring
> > > unavailable child nodes, and leaking a reference.
> >
> > FYI, I have a patch in my queue that replaces this code with traversing child nodes (via
> > for_each_available_child_of_node()) and only creating devices for ports actually defined in the device tree.
> 
> OK, thanks for letting me know!

I am assuming that we can treat Nikita's patch as being orthogonal to this one.

Reviewed-by: Simon Horman <horms@kernel.org>
patchwork-bot+netdevbpf@kernel.org Feb. 7, 2025, 8:10 p.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  5 Feb 2025 17:12:09 +0100 you wrote:
> Simplify rswitch_get_port_node() by using the
> for_each_available_child_of_node() helper instead of manually ignoring
> unavailable child nodes, and leaking a reference.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Tested on R-Car S4 Starter Kit, which has port 2 disabled.
> 
> [...]

Here is the summary with links:
  - [net-next] net: renesas: rswitch: Convert to for_each_available_child_of_node()
    https://git.kernel.org/netdev/net-next/c/7bca2b2d5fcc

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c
index 84d09a8973b78ee5..aba772e14555d308 100644
--- a/drivers/net/ethernet/renesas/rswitch.c
+++ b/drivers/net/ethernet/renesas/rswitch.c
@@ -1287,17 +1287,14 @@  static struct device_node *rswitch_get_port_node(struct rswitch_device *rdev)
 	if (!ports)
 		return NULL;
 
-	for_each_child_of_node(ports, port) {
+	for_each_available_child_of_node(ports, port) {
 		err = of_property_read_u32(port, "reg", &index);
 		if (err < 0) {
 			port = NULL;
 			goto out;
 		}
-		if (index == rdev->etha->index) {
-			if (!of_device_is_available(port))
-				port = NULL;
+		if (index == rdev->etha->index)
 			break;
-		}
 	}
 
 out: