Skip to content

Commit 2120db2

Browse files
DragonBluephauke
authored andcommitted
lantiq: fix mtdparsers refcount leak and memory leak
Release previously allocated memory and OF node before return. Signed-off-by: Shiji Yang <yangshiji66@outlook.com> Link: openwrt/openwrt#22276 Signed-off-by: Robert Marko <robimarko@gmail.com> (cherry picked from commit 4778e35) Link: openwrt/openwrt#22348 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
1 parent 214a657 commit 2120db2

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

target/linux/lantiq/patches-6.6/0101-find_active_root.patch

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Subject: [PATCH] find active root
55

66
Signed-off-by: Mathias Kresin <openwrt@kresin.me>
77
---
8-
drivers/mtd/parsers/ofpart_core.c | 49 ++++++++++++++++++++++++++++++-
9-
1 file changed, 48 insertions(+), 1 deletion(-)
8+
drivers/mtd/parsers/ofpart_core.c | 53 +++++++++++++++++++++++++++++++
9+
1 file changed, 53 insertions(+)
1010

1111
--- a/drivers/mtd/parsers/ofpart_core.c
1212
+++ b/drivers/mtd/parsers/ofpart_core.c
@@ -58,18 +58,22 @@ Signed-off-by: Mathias Kresin <openwrt@kresin.me>
5858

5959
/* Pull of_node from the master device node */
6060
mtd_node = mtd_get_of_node(master);
61-
@@ -95,7 +129,9 @@ static int parse_fixed_partitions(struct
62-
return 0;
61+
@@ -98,6 +132,14 @@ static int parse_fixed_partitions(struct
62+
if (!parts)
63+
return -ENOMEM;
6364

64-
parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
65-
- if (!parts)
6665
+ part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL);
66+
+ if (!part_nodes) {
67+
+ if (dedicated)
68+
+ of_node_put(ofpart_node);
69+
+ kfree(parts);
70+
+ return -ENOMEM;
71+
+ }
6772
+
68-
+ if (!parts || !part_nodes)
69-
return -ENOMEM;
70-
7173
i = 0;
72-
@@ -166,6 +202,11 @@ static int parse_fixed_partitions(struct
74+
for_each_child_of_node(ofpart_node, pp) {
75+
const __be32 *reg;
76+
@@ -166,6 +208,11 @@ static int parse_fixed_partitions(struct
7377
if (of_property_read_bool(pp, "slc-mode"))
7478
parts[i].add_flags |= MTD_SLC_ON_MLC_EMULATION;
7579

@@ -81,7 +85,7 @@ Signed-off-by: Mathias Kresin <openwrt@kresin.me>
8185
i++;
8286
}
8387

84-
@@ -175,6 +216,11 @@ static int parse_fixed_partitions(struct
88+
@@ -175,6 +222,11 @@ static int parse_fixed_partitions(struct
8589
if (quirks && quirks->post_parse)
8690
quirks->post_parse(master, parts, nr_parts);
8791

@@ -93,7 +97,7 @@ Signed-off-by: Mathias Kresin <openwrt@kresin.me>
9397
*pparts = parts;
9498
return nr_parts;
9599

96-
@@ -185,6 +231,7 @@ ofpart_fail:
100+
@@ -185,6 +237,7 @@ ofpart_fail:
97101
ofpart_none:
98102
of_node_put(pp);
99103
kfree(parts);

0 commit comments

Comments
 (0)