diff mbox series

media: platform: xilinx: Balance refcount to prevent memory leak

Message ID 20241102080327.463134-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Headers show
Series media: platform: xilinx: Balance refcount to prevent memory leak | expand

Commit Message

Joe Hattori Nov. 2, 2024, 8:03 a.m. UTC
In xtpg_parse_of(), the refcount of the device node "ports" is not
decremented after loop. This commit makes sure that of_node_put() is
called on the device node when leaving the function.

Fixes: a5562f65b137 ("[media] v4l: xilinx: Add Test Pattern Generator driver")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/media/platform/xilinx/xilinx-tpg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/xilinx/xilinx-tpg.c b/drivers/media/platform/xilinx/xilinx-tpg.c
index e05e528ffc6f..bb3ca16dd47b 100644
--- a/drivers/media/platform/xilinx/xilinx-tpg.c
+++ b/drivers/media/platform/xilinx/xilinx-tpg.c
@@ -718,7 +718,7 @@  static int xtpg_parse_of(struct xtpg_device *xtpg)
 
 	ports = of_get_child_by_name(node, "ports");
 	if (ports == NULL)
-		ports = node;
+		ports = of_node_get(node);
 
 	for_each_child_of_node(ports, port) {
 		const struct xvip_video_format *format;
@@ -731,6 +731,7 @@  static int xtpg_parse_of(struct xtpg_device *xtpg)
 		if (IS_ERR(format)) {
 			dev_err(dev, "invalid format in DT");
 			of_node_put(port);
+			of_node_put(ports);
 			return PTR_ERR(format);
 		}
 
@@ -740,6 +741,7 @@  static int xtpg_parse_of(struct xtpg_device *xtpg)
 		} else if (xtpg->vip_format != format) {
 			dev_err(dev, "in/out format mismatch in DT");
 			of_node_put(port);
+			of_node_put(ports);
 			return -EINVAL;
 		}
 
@@ -753,6 +755,7 @@  static int xtpg_parse_of(struct xtpg_device *xtpg)
 		/* Count the number of ports. */
 		nports++;
 	}
+	of_node_put(ports);
 
 	if (nports != 1 && nports != 2) {
 		dev_err(dev, "invalid number of ports %u\n", nports);