Skip to contentSkip to conversation

regmap: Fix potential memory leaks

PATCH New Faiz Abbas 2 participants 2 messages Nov 11, 2019 – Dec 4, 2019

lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

PATCH 1/1 regmap: Fix potential memory leaks

Free allocated memory in case of an error in regmap_init_mem() and regmap_init_mem_index().

---
 drivers/core/regmap.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/core/regmap.c +12 -4
index e9e55c9d16..a974744a61 100644
@@ -134,7 +134,7 @@ int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index)
 
 	ret = init_range(node, map->ranges, addr_len, size_len, index);
 	if (ret)
-		return ret;
+		goto err;
 
 	if (ofnode_read_bool(node, "little-endian"))
 		map->endianness = REGMAP_LITTLE_ENDIAN;
@@ -147,6 +147,10 @@ int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index)
 
 	*mapp = map;
 
+	return 0;
+err:
+	regmap_uninit(map);
+
 	return ret;
 }
 
@@ -158,6 +162,7 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
 	int addr_len, size_len, both_len;
 	int len;
 	int index;
+	int ret;
 
 	addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
 	if (addr_len < 0) {
@@ -200,10 +205,9 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
 
 	for (range = map->ranges, index = 0; count > 0;
 	     count--, range++, index++) {
-		int ret = init_range(node, range, addr_len, size_len, index);
-
+		ret = init_range(node, range, addr_len, size_len, index);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	if (ofnode_read_bool(node, "little-endian"))
@@ -218,6 +222,10 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
 	*mapp = map;
 
 	return 0;
+err:
+	regmap_uninit(map);
+
+	return ret;
 }
 #endif
 
Signature · 1 line
2.19.2
#1 lore raw

PATCH 1/1 regmap: Fix potential memory leaks

Quoted 4 lines · Faiz Abbas

Free allocated memory in case of an error in regmap_init_mem() and regmap_init_mem_index().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191203/70cefc49/attachment.sig>