From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/1] gpiolib: Make gpiod_put() error pointer aware
Date: Wed, 2 Apr 2025 18:20:00 +0300 [thread overview]
Message-ID: <20250402152000.1572764-1-andriy.shevchenko@linux.intel.com> (raw)
When non-optional GPIO is requested and failed, the variable that holds
the (invalid) descriptor can contain an error pointer. However, gpiod_put()
ignores that fact and tries to cleanup never requested descriptor.
Make sure gpiod_put() ignores that as well.
While at it, do the same for the gpiod_put_array().
Note, it arguable needs to be present in the stubs as those are usually
called when CONFIG_GPIOLIB=n and GPIOs are requested using gpiod_get_optional()
or similar APIs.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index eda4f51d6bb8..1e96b83d2670 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -5111,8 +5111,10 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_optional);
*/
void gpiod_put(struct gpio_desc *desc)
{
- if (desc)
- gpiod_free(desc);
+ if (IS_ERR_OR_NULL(desc))
+ return;
+
+ gpiod_free(desc);
}
EXPORT_SYMBOL_GPL(gpiod_put);
@@ -5124,6 +5126,9 @@ void gpiod_put_array(struct gpio_descs *descs)
{
unsigned int i;
+ if (IS_ERR_OR_NULL(descs))
+ return;
+
for (i = 0; i < descs->ndescs; i++)
gpiod_put(descs->desc[i]);
--
2.47.2
next reply other threads:[~2025-04-02 15:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 15:20 Andy Shevchenko [this message]
2025-04-03 6:58 ` [PATCH v1 1/1] gpiolib: Make gpiod_put() error pointer aware Bartosz Golaszewski
2025-04-03 8:04 ` Andy Shevchenko
2025-04-03 8:20 ` Bartosz Golaszewski
2025-04-03 11:16 ` Andy Shevchenko
2025-04-03 12:23 ` Bartosz Golaszewski
2025-04-03 13:22 ` Andy Shevchenko
2025-04-07 12:49 ` Bartosz Golaszewski
2025-04-07 13:45 ` Andy Shevchenko
2025-04-15 9:32 ` Linus Walleij
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=20250402152000.1572764-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=florian.fainelli@broadcom.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.