Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpio: gpiolib: fix refcount imbalance in gpiochip_setup_dev()
@ 2024-12-04 12:21 Joe Hattori
  2024-12-04 17:09 ` Linus Walleij
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Joe Hattori @ 2024-12-04 12:21 UTC (permalink / raw)
  To: linus.walleij, brgl; +Cc: linux-gpio, Joe Hattori

In gpiochip_setup_dev(), the refcount incremented in device_initialize()
is not decremented in the error path. Fix it by calling put_device().

Fixes: aab5c6f20023 ("gpio: set device type for GPIO chips")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/gpio/gpiolib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 679ed764cb14..6b2d50370ab7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -800,7 +800,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
 
 	ret = gcdev_register(gdev, gpio_devt);
 	if (ret)
-		return ret;
+		goto err_put_device;
 
 	ret = gpiochip_sysfs_register(gdev);
 	if (ret)
@@ -813,6 +813,8 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
 
 err_remove_device:
 	gcdev_unregister(gdev);
+err_put_device:
+	put_device(&gdev->dev);
 	return ret;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-12-17 14:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-04 12:21 [PATCH] gpio: gpiolib: fix refcount imbalance in gpiochip_setup_dev() Joe Hattori
2024-12-04 17:09 ` Linus Walleij
2024-12-05 12:09 ` Bartosz Golaszewski
2024-12-05 13:20 ` Andy Shevchenko
2024-12-05 13:23   ` Andy Shevchenko
2024-12-05 13:30   ` Bartosz Golaszewski
2024-12-06  8:53     ` Joe Hattori
2024-12-06 15:40       ` Andy Shevchenko
2024-12-17 14:50       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox