linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data()
@ 2022-07-04  9:13 Liang He
  2022-07-05 15:40 ` Bartosz Golaszewski
  2022-07-06 12:47 ` Linus Walleij
  0 siblings, 2 replies; 8+ messages in thread
From: Liang He @ 2022-07-04  9:13 UTC (permalink / raw)
  To: linus.walleij, brgl, linux-gpio, windhl

We should use of_node_get() when a new reference of device_node
is created. It is noted that the old reference stored in
'mm_gc->gc.of_node' should also be decreased.

Fixes: f141ed65f256 ("gpio: Move DT support code into drivers/gpio")
Signed-off-by: Liang He <windhl@126.com>
---
 drivers/gpio/gpiolib-of.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 3d6c3ffd5576..de100b0217da 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -860,7 +860,8 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 	if (mm_gc->save_regs)
 		mm_gc->save_regs(mm_gc);
 
-	mm_gc->gc.of_node = np;
+	of_node_put(mm_gc->gc.of_node);
+	mm_gc->gc.of_node = of_node_get(np);
 
 	ret = gpiochip_add_data(gc, data);
 	if (ret)
@@ -868,6 +869,7 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 
 	return 0;
 err2:
+	of_node_put(np);
 	iounmap(mm_gc->regs);
 err1:
 	kfree(gc->label);
-- 
2.25.1


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

end of thread, other threads:[~2022-07-11 12:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-04  9:13 [PATCH] gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data() Liang He
2022-07-05 15:40 ` Bartosz Golaszewski
2022-07-06  1:12   ` Liang He
2022-07-06 11:52     ` Andy Shevchenko
2022-07-06 12:01       ` Liang He
2022-07-06 12:47 ` Linus Walleij
2022-07-06 13:19   ` Liang He
2022-07-11 12:11     ` Linus Walleij

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).