dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] As the doc of of_parse_phandle() states: "The device_node pointer with refcount incremented. Use * of_node_put() on it when done."
@ 2025-09-03 14:00 Miaoqian Lin
  2025-09-03 17:31 ` [PATCH] As the doc of of_parse_phandle() states: … Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2025-09-03 14:00 UTC (permalink / raw)
  To: Thomas Zimmermann, Javier Martinez Canillas, Maarten Lankhorst,
	Maxime Ripard, David Airlie, Simona Vetter, Thierry Reding,
	dri-devel, linux-kernel
  Cc: linmq006, stable

The function doesn't calls
of_node_put() to release this reference, causing a reference leak.

Move the of_parse_phandle() call after devm_kzalloc() and add the missing
of_node_put() call immediately after of_address_to_resource() to properly
release the device node reference.

Found via static analysis.

Fixes: 9a10c7e6519b ("drm/simpledrm: Add support for system memory framebuffers")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/gpu/drm/sysfb/simpledrm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c
index 8530a3ef8a7a..f0bd7e958398 100644
--- a/drivers/gpu/drm/sysfb/simpledrm.c
+++ b/drivers/gpu/drm/sysfb/simpledrm.c
@@ -183,15 +183,16 @@ simplefb_get_memory_of(struct drm_device *dev, struct device_node *of_node)
 	struct resource *res;
 	int err;
 
-	np = of_parse_phandle(of_node, "memory-region", 0);
-	if (!np)
-		return NULL;
-
 	res = devm_kzalloc(dev->dev, sizeof(*res), GFP_KERNEL);
 	if (!res)
 		return ERR_PTR(-ENOMEM);
 
+	np = of_parse_phandle(of_node, "memory-region", 0);
+	if (!np)
+		return NULL;
+
 	err = of_address_to_resource(np, 0, res);
+	of_node_put(np);
 	if (err)
 		return ERR_PTR(err);
 
-- 
2.35.1


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

* Re: [PATCH] As the doc of of_parse_phandle() states: …
  2025-09-03 14:00 [PATCH] As the doc of of_parse_phandle() states: "The device_node pointer with refcount incremented. Use * of_node_put() on it when done." Miaoqian Lin
@ 2025-09-03 17:31 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-09-03 17:31 UTC (permalink / raw)
  To: Miaoqian Lin, dri-devel
  Cc: stable, LKML, David Airlie, Javier Martinez Canillas,
	Maarten Lankhorst, Maxime Ripard, Simona Vetter, Thierry Reding,
	Thomas Zimmermann

Please choose a more appropriate patch subject.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc4#n638


> Move the of_parse_phandle() call after devm_kzalloc() and add the missing
> of_node_put() call immediately after of_address_to_resource() to properly
> release the device node reference.

How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/of.h#L138


> Found via static analysis.

Which concrete software tools would be involved for this purpose?

Regards,
Markus


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

end of thread, other threads:[~2025-09-03 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 14:00 [PATCH] As the doc of of_parse_phandle() states: "The device_node pointer with refcount incremented. Use * of_node_put() on it when done." Miaoqian Lin
2025-09-03 17:31 ` [PATCH] As the doc of of_parse_phandle() states: … Markus Elfring

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