[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230622230217.793fe0c5@xps-13>
Date: Thu, 22 Jun 2023 23:02:17 +0200
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: Yang Rong <yangrong@...o.com>
Cc: Richard Weinberger <richard@....at>,
Vignesh Raghavendra <vigneshr@...com>,
linux-mtd@...ts.infradead.org (open list:MEMORY TECHNOLOGY DEVICES
(MTD)), linux-kernel@...r.kernel.org (open list),
opensource.kernel@...o.com, luhongfei@...o.com
Subject: Re: [PATCH] drivers: mtd: Fix potential memory leak in
mtd_check_of_node
Hello,
yangrong@...o.com wrote on Wed, 21 Jun 2023 10:43:22 +0800:
> The for_each_child_of_node API internally increases the reference count
> for each child node traversed. If a break statement is encountered inside
> the loop, it leaves one reference unbalanced leading to a memory leak.
>
> The function mtd_check_of_node in drivers/mtd/mtdcore.c uses such a loop
> and a break statement without a corresponding of_node_put.
>
> This patch fixes the potential memory leak by adding a call to
> of_node_put before the break statement inside the for_each_child_of_node
> loop in the function mtd_check_of_node.
I wanted to take this patch but it failed to apply cleanly. Please now
wait for -rc1 and send an updated v2.
>
> Signed-off-by: Yang Rong <yangrong@...o.com>
> ---
> drivers/mtd/mtdcore.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index e00b12aa5ec9..b02cb8b1a38d 100644
> --- 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
>
>
> ________________________________
> 本邮件及其附件内容可能含有机密和/或隐私信息,仅供指定个人或机构使用。若您非发件人指定收件人或其代理人,请勿使用、传播、复制或存储此邮件之任何内容或其附件。如您误收本邮件,请即以回复或电话方式通知发件人,并将原始邮件、附件及其所有复本删除。谢谢。
> The contents of this message and any attachments may contain confidential and/or privileged information and are intended exclusively for the addressee(s). If you are not the intended recipient of this message or their agent, please note that any use, dissemination, copying, or storage of this message or its attachments is not allowed. If you receive this message in error, please notify the sender by reply the message or phone and delete this message, any attachments and any copies immediately.
> Thank you
Thanks,
Miquèl
Powered by blists - more mailing lists