From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Khouloud Touil <ktouil@baylibre.com>,
Geert Uytterhoeven <geert@linux-m68k.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH v5 1/5] nvmem: fix memory leak in error path
Date: Fri, 21 Feb 2020 16:48:33 +0100 [thread overview]
Message-ID: <20200221154837.18845-2-brgl@bgdev.pl> (raw)
In-Reply-To: <20200221154837.18845-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
We need to free the ida mapping and nvmem struct if the write-protect
GPIO lookup fails.
Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/nvmem/core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 503da67dde06..2758d90d63b7 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -353,8 +353,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
else
nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
GPIOD_OUT_HIGH);
- if (IS_ERR(nvmem->wp_gpio))
- return ERR_CAST(nvmem->wp_gpio);
+ if (IS_ERR(nvmem->wp_gpio)) {
+ ida_simple_remove(&nvmem_ida, nvmem->id);
+ rval = PTR_ERR(nvmem->wp_gpio);
+ kfree(nvmem);
+ return ERR_PTR(rval);
+ }
kref_init(&nvmem->refcnt);
INIT_LIST_HEAD(&nvmem->cells);
--
2.25.0
next prev parent reply other threads:[~2020-02-21 15:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 15:48 [PATCH v5 0/5] nvmem/gpio: fix resource management Bartosz Golaszewski
2020-02-21 15:48 ` Bartosz Golaszewski [this message]
2020-02-21 16:42 ` [PATCH v5 1/5] nvmem: fix memory leak in error path Srinivas Kandagatla
2020-02-21 15:48 ` [PATCH v5 2/5] gpiolib: provide VALIDATE_DESC_PTR() macro Bartosz Golaszewski
2020-02-28 22:15 ` Linus Walleij
2020-02-21 15:48 ` [PATCH v5 3/5] gpiolib: use kref in gpio_desc Bartosz Golaszewski
2020-02-28 22:32 ` Linus Walleij
2020-02-29 20:15 ` Bartosz Golaszewski
2020-02-21 15:48 ` [PATCH v5 4/5] nvmem: increase the reference count of a gpio passed over config Bartosz Golaszewski
2020-02-21 15:48 ` [PATCH v5 5/5] nvmem: release the write-protect pin Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200221154837.18845-2-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=bgolaszewski@baylibre.com \
--cc=geert@linux-m68k.org \
--cc=ktouil@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).