Skip to contentSkip to conversation

v4l: xilinx-vipp: Fix refcount leak in xvip_graph_dma_init

PATCH In review Miaoqian Lin 2 participants 3 messages Jun 1, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l: xilinx-vipp: Fix refcount leak in xvip_graph_dma_init

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes df3305156f98 ("[media] v4l: xilinx: Add Xilinx Video IP core")
---
 drivers/media/platform/xilinx/xilinx-vipp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/xilinx/xilinx-vipp.c +2 -0
index f34f8b077e03..415579b63737 100644
@@ -483,10 +483,12 @@ static int xvip_graph_dma_init(struct xvip_composite_device *xdev)
 		ret = xvip_graph_dma_init_one(xdev, port);
 		if (ret < 0) {
 			of_node_put(port);
+			of_node_put(ports);
 			return ret;
 		}
 	}
 
+	of_node_put(ports);
 	return 0;
 }
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Lin,

Thank you for the patch.

Quoted 15 lines · Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes df3305156f98 ("[media] v4l: xilinx: Add Xilinx Video IP core")
---
 drivers/media/platform/xilinx/xilinx-vipp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/xilinx/xilinx-vipp.c +0 -0
index f34f8b077e03..415579b63737 100644

drivers/media/platform/xilinx/xilinx-vipp.c static int xvip_graph_dma_init(struct xvip_composite_device *xdev) · line 491

Quoted 9 lines
drivers/media/platform/xilinx/xilinx-vipp.c +2 -0
@@ -483,10 +483,12 @@ static int xvip_graph_dma_init(struct xvip_composite_device *xdev)
 		ret = xvip_graph_dma_init_one(xdev, port);
 		if (ret < 0) {
 			of_node_put(port);
+			of_node_put(ports);
 			return ret;
 		}
 	}
 
+	of_node_put(ports);

We could possibly simplify this a little bit by initializing ret to 0 when declaring it, replacing the "return ret" above by a break, and returning ret below. This would remove the need for the first of_node_put(ports) call above.

If you think that's a good idea I can make that change when applying this patch to my tree, otherwise I'll take it as-is.

In either case,

Quoted 3 lines
drivers/media/platform/xilinx/xilinx-vipp.c +0 -0
 	return 0;
 }
 
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi, Laurent

Quoted 28 lines · Laurent Pinchart

Hi Lin,

Thank you for the patch.

Quoted 23 lines · Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes df3305156f98 ("[media] v4l: xilinx: Add Xilinx Video IP core")
---
 drivers/media/platform/xilinx/xilinx-vipp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/xilinx/xilinx-vipp.c +1 -0
index f34f8b077e03..415579b63737 100644
@@ -483,10 +483,12 @@ static int xvip_graph_dma_init(struct xvip_composite_device *xdev)
 		ret = xvip_graph_dma_init_one(xdev, port);
 		if (ret < 0) {
 			of_node_put(port);
+			of_node_put(ports);
 			return ret;
 		}
 	}
 
Quoted 8 lines

drivers/media/platform/xilinx/xilinx-vipp.c static int xvip_graph_dma_init(struct xvip_composite_device *xdev) · line 491

Quoted 1 line
drivers/media/platform/xilinx/xilinx-vipp.c +1 -0
+	of_node_put(ports);

We could possibly simplify this a little bit by initializing ret to 0 when declaring it, replacing the "return ret" above by a break, and returning ret below. This would remove the need for the first of_node_put(ports) call above.

If you think that's a good idea I can make that change when applying this patch to my tree, otherwise I'll take it as-is.

Thanks for your review, I think your idea is good, we can do that to simplify code.

Quoted 7 lines

In either case,

Quoted 3 lines
drivers/media/platform/xilinx/xilinx-vipp.c +0 -0
 	return 0;
 }