Commit a93a676b authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Linus Walleij

pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()'

If 'krealloc()' fails, 'pctl->functions' is set to NULL.
We should instead use a temp variable in order to be able to free the
previously allocated memeory, in case of OOM.
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: default avatarMaxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent ee8edbf8
...@@ -1042,6 +1042,7 @@ static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl, ...@@ -1042,6 +1042,7 @@ static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl,
static int sunxi_pinctrl_build_state(struct platform_device *pdev) static int sunxi_pinctrl_build_state(struct platform_device *pdev)
{ {
struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev); struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev);
void *ptr;
int i; int i;
/* /*
...@@ -1108,13 +1109,15 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) ...@@ -1108,13 +1109,15 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
} }
/* And now allocated and fill the array for real */ /* And now allocated and fill the array for real */
pctl->functions = krealloc(pctl->functions, ptr = krealloc(pctl->functions,
pctl->nfunctions * sizeof(*pctl->functions), pctl->nfunctions * sizeof(*pctl->functions),
GFP_KERNEL); GFP_KERNEL);
if (!pctl->functions) { if (!ptr) {
kfree(pctl->functions); kfree(pctl->functions);
pctl->functions = NULL;
return -ENOMEM; return -ENOMEM;
} }
pctl->functions = ptr;
for (i = 0; i < pctl->desc->npins; i++) { for (i = 0; i < pctl->desc->npins; i++) {
const struct sunxi_desc_pin *pin = pctl->desc->pins + i; const struct sunxi_desc_pin *pin = pctl->desc->pins + i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment