Skip to contentSkip to conversation

pinctrl: pinctrl-mxs: Take care of frees if the kzalloc fails

PATCH In review Devendra Naga 3 participants 3 messages Jun 9, 2012 – Jun 12, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pinctrl: pinctrl-mxs: Take care of frees if the kzalloc fails

if there is no purecfg , the group pointer is allocated using kzalloc and if it fails to allocate, we wont free the new_map,

if config is true, we call kmemdup and if it
fails to do so we wont free the allocated group if there is no purecfg.

fix this by doing the frees of new_map pointer and group pointers.

---
 drivers/pinctrl/pinctrl-mxs.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-mxs.c +8 -3
index 556e45a..9d46303 100644
@@ -107,8 +107,10 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
 
 		/* Compose group name */
 		group = kzalloc(length, GFP_KERNEL);
-		if (!group)
-			return -ENOMEM;
+		if (!group) {
+			ret = -ENOMEM;
+			goto free;
+		}
 		snprintf(group, length, "%s.%d", np->name, reg);
 		new_map[i].data.mux.group = group;
 		i++;
@@ -118,7 +120,7 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
 		pconfig = kmemdup(&config, sizeof(config), GFP_KERNEL);
 		if (!pconfig) {
 			ret = -ENOMEM;
-			goto free;
+			goto free_group;
 		}
 
 		new_map[i].type = PIN_MAP_TYPE_CONFIGS_GROUP;
@@ -133,6 +135,9 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
 
 	return 0;
 
+free_group:
+	if (!purecfg)
+		free(group);
 free:
 	kfree(new_map);
 	return ret;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 9 lines · Devendra Naga

if there is no purecfg , the group pointer is allocated using kzalloc and if it fails to allocate, we wont free the new_map,

if config is true, we call kmemdup and if it
fails to do so we wont free the allocated group if there is no purecfg.

fix this by doing the frees of new_map pointer and group pointers.

Obviously correct so applied.

Dong, Shawn: any ACKs?

Yours,
Linus Walleij

Acked-by
#2 lore raw
Quoted 8 lines · Linus Walleij
Quoted 6 lines · Devendra Naga

if there is no purecfg , the group pointer is allocated using kzalloc and if it fails to allocate, we wont free the new_map,

if config is true, we call kmemdup and if it
fails to do so we wont free the allocated group if there is no purecfg.

Quoted 8 lines
Quoted 3 lines

fix this by doing the frees of new_map pointer and group pointers.

Obviously correct so applied.

Dong, Shawn: any ACKs?

Regards
Dong Aisheng