From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Khouloud Touil <ktouil@baylibre.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH 2/6] nvmem: fix memory leak in error path
Date: Mon, 17 Feb 2020 20:54:31 +0100 [thread overview]
Message-ID: <20200217195435.9309-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20200217195435.9309-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
We need to remove the ida mapping when returning from nvmem_register()
with an error.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/nvmem/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ef326f243f36..b0be03d5f240 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -353,7 +353,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
GPIOD_OUT_HIGH);
if (IS_ERR(nvmem->wp_gpio))
- return ERR_CAST(nvmem->wp_gpio);
+ goto err_ida_remove;
kref_init(&nvmem->refcnt);
@@ -430,6 +430,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
device_del(&nvmem->dev);
err_put_device:
put_device(&nvmem->dev);
+err_ida_remove:
+ ida_simple_remove(&nvmem_ida, nvmem->id);
return ERR_PTR(rval);
}
--
2.25.0
next prev parent reply other threads:[~2020-02-17 19:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 19:54 [PATCH 0/6] nvmem/gpio: fix resource management Bartosz Golaszewski
2020-02-17 19:54 ` [PATCH 1/6] gpiolib: use kref in gpio_desc Bartosz Golaszewski
2020-02-17 19:54 ` Bartosz Golaszewski [this message]
2020-02-18 9:31 ` [PATCH 2/6] nvmem: fix memory leak in error path Srinivas Kandagatla
2020-02-18 9:42 ` Srinivas Kandagatla
2020-02-18 9:44 ` Bartosz Golaszewski
2020-02-17 19:54 ` [PATCH 3/6] nvmem: remove a stray newline in nvmem_register() Bartosz Golaszewski
2020-02-18 9:31 ` Srinivas Kandagatla
2020-02-17 19:54 ` [PATCH 4/6] nvmem: add a newline for readability Bartosz Golaszewski
2020-02-18 9:31 ` Srinivas Kandagatla
2020-02-17 19:54 ` [PATCH 5/6] nvmem: release the write-protect pin Bartosz Golaszewski
2020-02-17 19:54 ` [PATCH 6/6] nvmem: increase the reference count of a gpio passed over config Bartosz Golaszewski
2020-02-17 21:13 ` Geert Uytterhoeven
2020-02-17 22:09 ` Bartosz Golaszewski
2020-02-17 19:56 ` [PATCH 0/6] nvmem/gpio: fix resource management 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=20200217195435.9309-3-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=bgolaszewski@baylibre.com \
--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).