* [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()'
@ 2018-10-16 6:22 Christophe JAILLET
2018-10-16 6:59 ` Maxime Ripard
2018-10-16 8:04 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2018-10-16 6:22 UTC (permalink / raw)
To: maxime.ripard, wens, linus.walleij
Cc: linux-arm-kernel, linux-gpio, linux-kernel, kernel-janitors,
Christophe JAILLET
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: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 4d9bf9b3e9f3..a895c70def68 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -1042,6 +1042,7 @@ static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl,
static int sunxi_pinctrl_build_state(struct platform_device *pdev)
{
struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev);
+ void *ptr;
int i;
/*
@@ -1109,13 +1110,15 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
}
/* And now allocated and fill the array for real */
- pctl->functions = krealloc(pctl->functions,
- pctl->nfunctions * sizeof(*pctl->functions),
- GFP_KERNEL);
- if (!pctl->functions) {
+ ptr = krealloc(pctl->functions,
+ pctl->nfunctions * sizeof(*pctl->functions),
+ GFP_KERNEL);
+ if (!ptr) {
kfree(pctl->functions);
+ pctl->functions = NULL;
return -ENOMEM;
}
+ pctl->functions = ptr;
for (i = 0; i < pctl->desc->npins; i++) {
const struct sunxi_desc_pin *pin = pctl->desc->pins + i;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()'
2018-10-16 6:22 [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()' Christophe JAILLET
@ 2018-10-16 6:59 ` Maxime Ripard
2018-10-16 8:04 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2018-10-16 6:59 UTC (permalink / raw)
To: Christophe JAILLET
Cc: wens, linus.walleij, linux-arm-kernel, linux-gpio, linux-kernel,
kernel-janitors
On Tue, Oct 16, 2018 at 08:22:28AM +0200, Christophe JAILLET wrote:
> 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: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()'
2018-10-16 6:22 [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()' Christophe JAILLET
2018-10-16 6:59 ` Maxime Ripard
@ 2018-10-16 8:04 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2018-10-16 8:04 UTC (permalink / raw)
To: Christophe Jaillet
Cc: Maxime Ripard, Chen-Yu Tsai, Linux ARM, open list:GPIO SUBSYSTEM,
linux-kernel, kernel-janitors
On Tue, Oct 16, 2018 at 8:22 AM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
> 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: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Patch applied with Maxime's ACK.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-16 8:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-16 6:22 [PATCH] pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()' Christophe JAILLET
2018-10-16 6:59 ` Maxime Ripard
2018-10-16 8:04 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).