[PATCH] media: platform: xilinx: Balance refcount to prevent memory leak
Joe Hattori
joe at pf.is.s.u-tokyo.ac.jp
Sat Nov 2 01:03:27 PDT 2024
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 at pf.is.s.u-tokyo.ac.jp>
---
drivers/media/platform/xilinx/xilinx-tpg.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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);
--
2.34.1
More information about the linux-arm-kernel
mailing list