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.

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>
This commit is contained in:
Devendra Naga 2012-06-09 17:31:23 +05:30 committed by Linus Walleij
parent 67695f2eae
commit 0bf7481852

View File

@ -107,8 +107,10 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
/* Compose group name */ /* Compose group name */
group = kzalloc(length, GFP_KERNEL); group = kzalloc(length, GFP_KERNEL);
if (!group) if (!group) {
return -ENOMEM; ret = -ENOMEM;
goto free;
}
snprintf(group, length, "%s.%d", np->name, reg); snprintf(group, length, "%s.%d", np->name, reg);
new_map[i].data.mux.group = group; new_map[i].data.mux.group = group;
i++; i++;
@ -118,7 +120,7 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
pconfig = kmemdup(&config, sizeof(config), GFP_KERNEL); pconfig = kmemdup(&config, sizeof(config), GFP_KERNEL);
if (!pconfig) { if (!pconfig) {
ret = -ENOMEM; ret = -ENOMEM;
goto free; goto free_group;
} }
new_map[i].type = PIN_MAP_TYPE_CONFIGS_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; return 0;
free_group:
if (!purecfg)
free(group);
free: free:
kfree(new_map); kfree(new_map);
return ret; return ret;