2022-06-06 04:32:26

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] mtd: parsers: ofpart: Fix refcount leak in bcm4908_partitions_fw_offset

of_find_node_by_path() returns a node pointer with refcount incremented,
we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes: bb17230c61a6 ("mtd: parsers: ofpart: support BCM4908 fixed partitions")
Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/mtd/parsers/ofpart_bcm4908.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/parsers/ofpart_bcm4908.c b/drivers/mtd/parsers/ofpart_bcm4908.c
index 0eddef4c198e..bb072a0940e4 100644
--- a/drivers/mtd/parsers/ofpart_bcm4908.c
+++ b/drivers/mtd/parsers/ofpart_bcm4908.c
@@ -35,12 +35,15 @@ static long long bcm4908_partitions_fw_offset(void)
err = kstrtoul(s + len + 1, 0, &offset);
if (err) {
pr_err("failed to parse %s\n", s + len + 1);
+ of_node_put(root);
return err;
}

+ of_node_put(root);
return offset << 10;
}

+ of_node_put(root);
return -ENOENT;
}

--
2.25.1


2022-06-09 13:47:12

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH] mtd: parsers: ofpart: Fix refcount leak in bcm4908_partitions_fw_offset

On Sun, 2022-06-05 at 07:07:23 UTC, Miaoqian Lin wrote:
> of_find_node_by_path() returns a node pointer with refcount incremented,
> we should use of_node_put() on it when not need anymore.
> Add missing of_node_put() to avoid refcount leak.
>
> Fixes: bb17230c61a6 ("mtd: parsers: ofpart: support BCM4908 fixed partitions")
> Signed-off-by: Miaoqian Lin <[email protected]>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel