lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250402152000.1572764-1-andriy.shevchenko@linux.intel.com>
Date: Wed,  2 Apr 2025 18:20:00 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
	linux-gpio@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Linus Walleij <linus.walleij@...aro.org>,
	Bartosz Golaszewski <brgl@...ev.pl>,
	Florian Fainelli <florian.fainelli@...adcom.com>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [PATCH v1 1/1] gpiolib: Make gpiod_put() error pointer aware

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@...ux.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ