回复: [PATCH net v2] net:thunderx:Fix resource leaks in device_for_each_child_node() loops

王明-软件底层技术部 machel at vivo.com
Wed Jul 5 20:40:43 PDT 2023


Hi
They all come from device for each child node().

-----邮件原件-----
发件人: Benjamin Poirier <benjamin.poirier at gmail.com> 
发送时间: 2023年7月6日 3:29
收件人: 王明-软件底层技术部 <machel at vivo.com>
抄送: Sunil Goutham <sgoutham at marvell.com>; David S. Miller <davem at davemloft.net>; Eric Dumazet <edumazet at google.com>; Jakub Kicinski <kuba at kernel.org>; Paolo Abeni <pabeni at redhat.com>; linux-arm-kernel at lists.infradead.org; netdev at vger.kernel.org; linux-kernel at vger.kernel.org; opensource.kernel <opensource.kernel at vivo.com>
主题: Re: [PATCH net v2] net:thunderx:Fix resource leaks in device_for_each_child_node() loops

[Some people who received this message don't often get email from benjamin.poirier at gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

On 2023-07-05 22:34 +0800, Wang Ming wrote:
> The device_for_each_child_node() loop in
> bgx_init_of_phy() function should have
> wnode_handle_put() before break
 ^
 fwnode_handle_put()

> which could avoid resource leaks.
> This patch could fix this bug.
>
> Signed-off-by: Wang Ming <machel at vivo.com>
> ---
>  drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c 
> b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> index a317feb8decb..dad32d36a015 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> @@ -1478,8 +1478,10 @@ static int bgx_init_of_phy(struct bgx *bgx)
>                * cannot handle it, so exit the loop.
>                */
>               node = to_of_node(fwn);
> -             if (!node)
> +             if (!node) {
> +                     fwnode_handle_put(fwn);
>                       break;
> +             }

Fixes: eee326fd8334 ("net: thunderx: bgx: Use standard firmware node infrastructure.") ?

>
>               of_get_mac_address(node, bgx->lmac[lmac].mac);
>
> @@ -1503,6 +1505,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
>               lmac++;
>               if (lmac == bgx->max_lmac) {
>                       of_node_put(node);
> +                     fwnode_handle_put(fwn);

\ fwnode_handle_put
        \ of_fwnode_put
                of_node_put(to_of_node(fwnode));

With your patch, there are now two references released on 'node' (two
of_node_put(node) calls).
One reference is from device_for_each_child_node(), where was the other reference taken?


More information about the linux-arm-kernel mailing list