diff mbox series

drivers: bus: Fix resource leaks in for_each_available_child_of_node loop

Message ID 20230706071310.38388-1-luhongfei@vivo.com (mailing list archive)
State New, archived
Headers show
Series drivers: bus: Fix resource leaks in for_each_available_child_of_node loop | expand

Commit Message

Lu Hongfei July 6, 2023, 7:13 a.m. UTC
Ensure child node references are decremented properly in
the error path.

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
 drivers/bus/imx-weim.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Geert Uytterhoeven July 6, 2023, 7:43 a.m. UTC | #1
Hi Lu,

Thanks for your patch!

On Thu, Jul 6, 2023 at 9:13 AM Lu Hongfei <luhongfei@vivo.com> wrote:
> Ensure child node references are decremented properly in
> the error path.

Which error path?

>
> Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
> ---
>  drivers/bus/imx-weim.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index 52a5d0447390..d05472f7c20f 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -251,6 +251,7 @@ static int weim_parse_dt(struct platform_device *pdev)
>                 else
>                         have_child = 1;
>         }
> +       of_node_put(child);

This is not an error path.

for_each_available_child_of_node() walks a list, getting a reference
to each child, and releasing the reference afterwards.

Have you tested this patch?
I expect the of_node_put() to trigger a refcount underflow error
message on the console.

>
>         if (have_child)
>                 ret = of_platform_default_populate(pdev->dev.of_node,

Gr{oetje,eeting}s,

                        Geert
Lu Hongfei July 6, 2023, 7:50 a.m. UTC | #2
在 2023/7/6 15:43, Geert Uytterhoeven 写道:
> Hi Lu,
>
> Thanks for your patch!
>
> On Thu, Jul 6, 2023 at 9:13 AM Lu Hongfei <luhongfei@vivo.com> wrote:
>> Ensure child node references are decremented properly in
>> the error path.
> Which error path?
>
>> Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
>> ---
>>   drivers/bus/imx-weim.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
>> index 52a5d0447390..d05472f7c20f 100644
>> --- a/drivers/bus/imx-weim.c
>> +++ b/drivers/bus/imx-weim.c
>> @@ -251,6 +251,7 @@ static int weim_parse_dt(struct platform_device *pdev)
>>                  else
>>                          have_child = 1;
>>          }
>> +       of_node_put(child);
> This is not an error path.
>
> for_each_available_child_of_node() walks a list, getting a reference
> to each child, and releasing the reference afterwards.
>
> Have you tested this patch?
> I expect the of_node_put() to trigger a refcount underflow error
> message on the console.

Sorry about this.

I will continue to increase my business capabilities and reduce such 
errors in the future.

Please ignore this incorrect patch.

Thanks.

>>          if (have_child)
>>                  ret = of_platform_default_populate(pdev->dev.of_node,
> Gr{oetje,eeting}s,
>
>                          Geert
>
Geert Uytterhoeven July 6, 2023, 7:53 a.m. UTC | #3
On Thu, Jul 6, 2023 at 9:43 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Thu, Jul 6, 2023 at 9:13 AM Lu Hongfei <luhongfei@vivo.com> wrote:
> > Ensure child node references are decremented properly in
> > the error path.
>
> Which error path?
>
> >
> > Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
> > ---
> >  drivers/bus/imx-weim.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> > index 52a5d0447390..d05472f7c20f 100644
> > --- a/drivers/bus/imx-weim.c
> > +++ b/drivers/bus/imx-weim.c
> > @@ -251,6 +251,7 @@ static int weim_parse_dt(struct platform_device *pdev)
> >                 else
> >                         have_child = 1;
> >         }
> > +       of_node_put(child);
>
> This is not an error path.
>
> for_each_available_child_of_node() walks a list, getting a reference
> to each child, and releasing the reference afterwards.

FTR, calling of_node_put() manually is only needed when breaking
out of for_each_available_child_of_node().

>
> Have you tested this patch?
> I expect the of_node_put() to trigger a refcount underflow error
> message on the console.
>
> >
> >         if (have_child)
> >                 ret = of_platform_default_populate(pdev->dev.of_node,

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 52a5d0447390..d05472f7c20f 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -251,6 +251,7 @@  static int weim_parse_dt(struct platform_device *pdev)
 		else
 			have_child = 1;
 	}
+	of_node_put(child);
 
 	if (have_child)
 		ret = of_platform_default_populate(pdev->dev.of_node,