Skip to content

Commit

Permalink
pinctrl: pinctrl-mxs: Take care of frees if the kzalloc fails
Browse files Browse the repository at this point in the history
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.

Acked-by: Dong Aisheng <dong.aisheng@linaro.org>
Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Devendra Naga authored and Linus Walleij committed Jun 12, 2012
1 parent 67695f2 commit 0bf7481
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/pinctrl/pinctrl-mxs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 0bf7481

Please sign in to comment.