RE: [PATCH] net: ethernet: renesas: rswitch: fix device_node refcount leak in rswitch_get_port_node()

Michael Dege <[email protected]>
Newsgroups org.kernel.vger.linux-renesas-soc,org.kernel.vger.netdev
Message-ID <TY4PR01MB14282B3217D649F712BAD67BB82DB2@TY4PR01MB14282.jpnprd01.prod.outlook.com>
Hello Manush,

Thank you for your patch.

> -----Original Message-----
> From: Manush Prajwal <[email protected]>
> Sent: Thursday, August 13, 2026 1:11 PM
> To: Yoshihiro Shimoda <[email protected]>
> Cc: [email protected]; [email protected]; Manush Prajwal
> <[email protected]>
> Subject: [PATCH] net: ethernet: renesas: rswitch: fix device_node refcount leak in
> rswitch_get_port_node()
> 
> [You don't often get email from [email protected]. Learn why this is important at
> https://aka.ms/LearnAboutSenderIdentification ]
> 
> On an of_property_read_u32() failure, rswitch_get_port_node() sets port to NULL and jumps to the out
> label before releasing the reference the for_each_available_child_of_node() iterator was holding on
> it. Once port is overwritten with NULL, that reference can never be released since out: only puts
> "ports", the parent node. Call
> of_node_put(port) before clearing it.
> 
> Signed-off-by: Manush Prajwal <[email protected]>
> ---
>  drivers/net/ethernet/renesas/rswitch_main.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c
> index 6fe9648163..ffdc42f430 100644
> --- a/drivers/net/ethernet/renesas/rswitch_main.c
> +++ b/drivers/net/ethernet/renesas/rswitch_main.c
> @@ -1315,6 +1315,7 @@ static struct device_node *rswitch_get_port_node(struct rswitch_device *rdev)
>         for_each_available_child_of_node(ports, port) {
>                 err = of_property_read_u32(port, "reg", &index);
>                 if (err < 0) {
> +                       of_node_put(port);

I am not sure why you are adding this here. The code jumps to the label "out" and that is where 
"of_node_put(port)" is called. Is there a reason why you want to call this twice in a row?

Best regards,

Michael


>                         port = NULL;
>                         goto out;
>                 }
> --
> 2.46.2.windows.1
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.