All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sbus: fix device node leak in openprom_init()
@ 2026-12-04 12:40 Yuwei Chen
  2026-12-04 13:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yuwei Chen @ 2026-12-04 12:40 UTC (permalink / raw)
  To: David S . Miller, Andreas Larsson; +Cc: sparclinux

openprom_init() looks up "/" with of_find_node_by_path() and passes
that node to of_get_child_by_name(). The child lookup takes its own
reference on "options" and does not drop the root. The root pointer
is discarded. "options" is kept for the life of the driver and is not
dropped in openprom_cleanup().

The root reference has been leaked since sparc started using the
generic OF lookup, which increments the refcount. The "options"
reference was added when the open-coded sibling walk was replaced by
of_get_child_by_name().

Drop the root after the child lookup. Drop "options" when the module
unloads.

Fixes: a88b5ba8bd8a ("sparc,sparc64: unify kernel/")
Fixes: df58f37b5d8f ("sbus: Use of_get_child_by_name helper")
Cc: stable@vger.kernel.org
Signed-off-by: Yuwei Chen <2522445001@qq.com>
---
 drivers/sbus/char/openprom.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 0b90a2450429..db55c3c0c34f 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -702,12 +702,15 @@ static struct miscdevice openprom_dev = {
 static int __init openprom_init(void)
 {
 	int err;
+	struct device_node *root;
 
 	err = misc_register(&openprom_dev);
 	if (err)
 		return err;
 
-	options_node = of_get_child_by_name(of_find_node_by_path("/"), "options");
+	root = of_find_node_by_path("/");
+	options_node = of_get_child_by_name(root, "options");
+	of_node_put(root);
 	if (!options_node) {
 		misc_deregister(&openprom_dev);
 		return -EIO;
@@ -719,6 +722,7 @@ static int __init openprom_init(void)
 static void __exit openprom_cleanup(void)
 {
 	misc_deregister(&openprom_dev);
+	of_node_put(options_node);
 }
 
 module_init(openprom_init);
-- 
2.53.0.windows.2

base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29


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

end of thread, other threads:[~2026-12-04 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 12:40 [PATCH] sbus: fix device node leak in openprom_init() Yuwei Chen
2026-12-04 13:23 ` sashiko-bot

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.