From 39f757752458dffb04de36d76835a26fe17cc7bb Mon Sep 17 00:00:00 2001 From: Shiji Yang Date: Fri, 6 Mar 2026 08:36:01 +0800 Subject: [PATCH] lantiq: fix mtdparsers refcount leak and memory leak Release previously allocated memory and OF node before return. Signed-off-by: Shiji Yang Link: https://github.com/openwrt/openwrt/pull/22276 Signed-off-by: Robert Marko (cherry picked from commit 4778e35464d4ae38f2dc508be5caf3861e1799b3) Link: https://github.com/openwrt/openwrt/pull/22699 Signed-off-by: Hauke Mehrtens --- .../patches-6.12/101-find_active_root.patch | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/target/linux/lantiq/patches-6.12/101-find_active_root.patch b/target/linux/lantiq/patches-6.12/101-find_active_root.patch index 99e187a012..b5fefbae09 100644 --- a/target/linux/lantiq/patches-6.12/101-find_active_root.patch +++ b/target/linux/lantiq/patches-6.12/101-find_active_root.patch @@ -5,8 +5,8 @@ Subject: [PATCH] find active root Signed-off-by: Mathias Kresin --- - drivers/mtd/parsers/ofpart_core.c | 49 ++++++++++++++++++++++++++++++- - 1 file changed, 48 insertions(+), 1 deletion(-) + drivers/mtd/parsers/ofpart_core.c | 53 +++++++++++++++++++++++++++++++ + 1 file changed, 53 insertions(+) --- a/drivers/mtd/parsers/ofpart_core.c +++ b/drivers/mtd/parsers/ofpart_core.c @@ -58,18 +58,22 @@ Signed-off-by: Mathias Kresin /* Pull of_node from the master device node */ mtd_node = mtd_get_of_node(master); -@@ -95,7 +129,9 @@ static int parse_fixed_partitions(struct - return 0; - - parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL); -- if (!parts) -+ part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL); -+ -+ if (!parts || !part_nodes) +@@ -98,6 +132,14 @@ static int parse_fixed_partitions(struct + if (!parts) return -ENOMEM; ++ part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL); ++ if (!part_nodes) { ++ if (dedicated) ++ of_node_put(ofpart_node); ++ kfree(parts); ++ return -ENOMEM; ++ } ++ i = 0; -@@ -166,6 +202,11 @@ static int parse_fixed_partitions(struct + for_each_child_of_node(ofpart_node, pp) { + const __be32 *reg; +@@ -166,6 +208,11 @@ static int parse_fixed_partitions(struct if (of_property_read_bool(pp, "slc-mode")) parts[i].add_flags |= MTD_SLC_ON_MLC_EMULATION; @@ -81,7 +85,7 @@ Signed-off-by: Mathias Kresin i++; } -@@ -175,6 +216,11 @@ static int parse_fixed_partitions(struct +@@ -175,6 +222,11 @@ static int parse_fixed_partitions(struct if (quirks && quirks->post_parse) quirks->post_parse(master, parts, nr_parts); @@ -93,7 +97,7 @@ Signed-off-by: Mathias Kresin *pparts = parts; return nr_parts; -@@ -185,6 +231,7 @@ ofpart_fail: +@@ -185,6 +237,7 @@ ofpart_fail: ofpart_none: of_node_put(pp); kfree(parts);