Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1494062 > unrolled thread
| Started by | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| First post | 2016-09-30 14:20 +0200 |
| Last post | 2016-10-10 10:50 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 3/3] pinctrl: sunxi: Don't leak memory in case krealloc() failes Johannes Thumshirn <jthumshirn@suse.de> - 2016-09-30 14:20 +0200
Re: [PATCH 3/3] pinctrl: sunxi: Don't leak memory in case krealloc() failes Linus Walleij <linus.walleij@linaro.org> - 2016-10-10 10:50 +0200
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Date | 2016-09-30 14:20 +0200 |
| Subject | [PATCH 3/3] pinctrl: sunxi: Don't leak memory in case krealloc() failes |
| Message-ID | <sn4Xf-1Ge-3@gated-at.bofh.it> |
If krealloc() fails there's no way of freeing the memory previously allocated
for pctl->functions as it is overwritten by krealloc()'s return value. Fix
this by assigning the return value to a temporary variable first so we can do
error handling (which we didn't do at all before).
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 54455af..57dd09b 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -787,6 +787,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);
+ struct sunxi_pinctrl_function *functions;
int i;
pctl->ngroups = pctl->desc->npins;
@@ -833,9 +834,14 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
}
}
- pctl->functions = krealloc(pctl->functions,
- pctl->nfunctions * sizeof(*pctl->functions),
- GFP_KERNEL);
+ functions = krealloc(pctl->functions,
+ pctl->nfunctions * sizeof(*pctl->functions),
+ GFP_KERNEL);
+ if (!functions) {
+ kfree(pctl->functions);
+ return -ENOMEM;
+ }
+ pctl->functions = functions;
for (i = 0; i < pctl->desc->npins; i++) {
const struct sunxi_desc_pin *pin = pctl->desc->pins + i;
--
1.8.5.6
[toc] | [next] | [standalone]
| From | Linus Walleij <linus.walleij@linaro.org> |
|---|---|
| Date | 2016-10-10 10:50 +0200 |
| Message-ID | <sqErw-7rt-31@gated-at.bofh.it> |
| In reply to | #1494062 |
On Fri, Sep 30, 2016 at 2:14 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote: > If krealloc() fails there's no way of freeing the memory previously allocated > for pctl->functions as it is overwritten by krealloc()'s return value. Fix > this by assigning the return value to a temporary variable first so we can do > error handling (which we didn't do at all before). > > 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