2023-07-11 02:34:15

by Yang Rong

[permalink] [raw]
Subject: [PATCH v3] mtd: core: Fix resource leak in a for_each_child_of_node() loop

Ensure child node references are properly decremented in the error path
of this function implementation.

Fixes: 2df11f00100d ("mtd: core: try to find OF node for every MTD partition")
Signed-off-by: Yang Rong <[email protected]>
---
v2: https://lore.kernel.org/all/[email protected]/
The modifications made copared to the previous version are as follows:
1.Optimized the expression of the Subject, making it more accurate.
2.Optimized the content of the commit message.
3.Add the tag "Fixes".

drivers/mtd/mtdcore.c | 1 +
1 file changed, 1 insertion(+)
mode change 100644 => 100755 drivers/mtd/mtdcore.c

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index e00b12aa5ec9..b02cb8b1a38d
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -591,6 +591,7 @@ static void mtd_check_of_node(struct mtd_info *mtd)
if (plen == mtd_name_len &&
!strncmp(mtd->name, pname + offset, plen)) {
mtd_set_of_node(mtd, mtd_dn);
+ of_node_put(mtd_dn);
break;
}
}
--
2.35.3



2023-07-11 16:46:00

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH v3] mtd: core: Fix resource leak in a for_each_child_of_node() loop

----- Ursprüngliche Mail -----
> Von: "Markus Elfring" <[email protected]>
>> v2: https://lore.kernel.org/all/[email protected]/
>> The modifications made copared to the previous version are as follows:
>
> How do you think about the omission of a line here
> (so that a repeated typo can be avoided)?
>
> Would the subsequent enumeration look a bit nicer if each text item
> will be delimited by a space character?

Markus, just stop it.

Thanks,
//richard

2023-07-11 18:17:43

by Rafał Miłecki

[permalink] [raw]
Subject: Re: [PATCH v3] mtd: core: Fix resource leak in a for_each_child_of_node() loop

On 2023-07-11 04:03, Yang Rong wrote:
> Ensure child node references are properly decremented in the error path
> of this function implementation.

Nitpicking: it's actually a /success/ code path that misses
of_node_put().


> Fixes: 2df11f00100d ("mtd: core: try to find OF node for every MTD
> partition")
> Signed-off-by: Yang Rong <[email protected]>

Acked-by: Rafał Miłecki <[email protected]>


> ---
> v2:
> https://lore.kernel.org/all/[email protected]/
> The modifications made copared to the previous version are as follows:
> 1.Optimized the expression of the Subject, making it more accurate.
> 2.Optimized the content of the commit message.
> 3.Add the tag "Fixes".
>
> drivers/mtd/mtdcore.c | 1 +
> 1 file changed, 1 insertion(+)
> mode change 100644 => 100755 drivers/mtd/mtdcore.c
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index e00b12aa5ec9..b02cb8b1a38d
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -591,6 +591,7 @@ static void mtd_check_of_node(struct mtd_info *mtd)
> if (plen == mtd_name_len &&
> !strncmp(mtd->name, pname + offset, plen)) {
> mtd_set_of_node(mtd, mtd_dn);
> + of_node_put(mtd_dn);
> break;
> }
> }

2023-07-12 13:28:09

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v3] mtd: core: Fix resource leak in a for_each_child_of_node() loop

Hi Rafał,

[email protected] wrote on Tue, 11 Jul 2023 18:37:42 +0200:

> On 2023-07-11 04:03, Yang Rong wrote:
> > Ensure child node references are properly decremented in the error path
> > of this function implementation.
>
> Nitpicking: it's actually a /success/ code path that misses
> of_node_put().

Please also add:

Cc: stable...

>
>
> > Fixes: 2df11f00100d ("mtd: core: try to find OF node for every MTD > partition")
> > Signed-off-by: Yang Rong <[email protected]>
>
> Acked-by: Rafał Miłecki <[email protected]>
>
>
> > ---
> > v2: > https://lore.kernel.org/all/[email protected]/
> > The modifications made copared to the previous version are as follows:
> > 1.Optimized the expression of the Subject, making it more accurate.
> > 2.Optimized the content of the commit message.
> > 3.Add the tag "Fixes".
> >
> > drivers/mtd/mtdcore.c | 1 +
> > 1 file changed, 1 insertion(+)
> > mode change 100644 => 100755 drivers/mtd/mtdcore.c
> >
> > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> > index e00b12aa5ec9..b02cb8b1a38d
> > --- a/drivers/mtd/mtdcore.c
> > +++ b/drivers/mtd/mtdcore.c
> > @@ -591,6 +591,7 @@ static void mtd_check_of_node(struct mtd_info *mtd)
> > if (plen == mtd_name_len &&
> > !strncmp(mtd->name, pname + offset, plen)) {
> > mtd_set_of_node(mtd, mtd_dn);
> > + of_node_put(mtd_dn);
> > break;
> > }
> > }


Thanks,
Miquèl