Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1494069 > unrolled thread

[PATCH 2/3] pinctrl: berlin: Don't leak memory if krealloc() fails

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2016-09-30 14:20 +0200
Last post2016-10-10 10:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 2/3] pinctrl: berlin: Don't leak memory if krealloc() fails Johannes Thumshirn <jthumshirn@suse.de> - 2016-09-30 14:20 +0200
    Re: [PATCH 2/3] pinctrl: berlin: Don't leak memory if krealloc() fails Linus Walleij <linus.walleij@linaro.org> - 2016-10-10 10:50 +0200

#1494069 — [PATCH 2/3] pinctrl: berlin: Don't leak memory if krealloc() fails

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2016-09-30 14:20 +0200
Subject[PATCH 2/3] pinctrl: berlin: Don't leak memory if krealloc() fails
Message-ID<sn4Xf-1Ge-17@gated-at.bofh.it>
We're directly assigning krealoc()'s return value to pctrl->functions instead
of using a temporary value to handle error checking. This leaks memory in case
krealloc() failes. While we're at it, implement error handling for failed
allocations at all.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/pinctrl/berlin/berlin.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c
index 8f0dc02..76281c8 100644
--- a/drivers/pinctrl/berlin/berlin.c
+++ b/drivers/pinctrl/berlin/berlin.c
@@ -208,6 +208,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
 	struct berlin_pinctrl *pctrl = platform_get_drvdata(pdev);
 	struct berlin_desc_group const *desc_group;
 	struct berlin_desc_function const *desc_function;
+	struct berlin_pinctrl_function *functions;
 	int i, max_functions = 0;
 
 	pctrl->nfunctions = 0;
@@ -236,9 +237,14 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
 		}
 	}
 
-	pctrl->functions = krealloc(pctrl->functions,
-				    pctrl->nfunctions * sizeof(*pctrl->functions),
-				    GFP_KERNEL);
+	functions = krealloc(pctrl->functions,
+			     pctrl->nfunctions * sizeof(*pctrl->functions),
+			     GFP_KERNEL);
+	if (!functions) {
+		kfree(pctrl->functions);
+		return -ENOMEM;
+	}
+	pctrl->functions = functions;
 
 	/* map functions to theirs groups */
 	for (i = 0; i < pctrl->desc->ngroups; i++) {
-- 
1.8.5.6

[toc] | [next] | [standalone]


#1498170

FromLinus Walleij <linus.walleij@linaro.org>
Date2016-10-10 10:50 +0200
Message-ID<sqErw-7rt-15@gated-at.bofh.it>
In reply to#1494069
On Fri, Sep 30, 2016 at 2:13 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote:

> We're directly assigning krealoc()'s return value to pctrl->functions instead
> of using a temporary value to handle error checking. This leaks memory in case
> krealloc() failes. While we're at it, implement error handling for failed
> allocations at all.
>
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>

Patch applied.

Yours,
Linus Walleij

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web