Re: [PATCH 4/4] media: xilinx: fix leaked of_node references
From: Hans Verkuil
Date: Wed May 29 2019 - 05:00:24 EST
On 5/6/19 9:05 AM, Wen Yang wrote:
> The call to of_get_child_by_name returns a node pointer with refcount
> incremented thus it must be explicitly decremented after the last
> usage.
>
> Detected by coccinelle with the following warnings:
> drivers/media/platform/xilinx/xilinx-vipp.c:487:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 477, but without a corresponding object release within this function.
> drivers/media/platform/xilinx/xilinx-vipp.c:491:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 477, but without a corresponding object release within this function.
>
> Signed-off-by: Wen Yang <wen.yang99@xxxxxxxxxx>
> Cc: Patrice Chotard <patrice.chotard@xxxxxx>
> Cc: Hyun Kwon <hyun.kwon@xxxxxxxxxx>
> Cc: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
> Cc: Michal Simek <michal.simek@xxxxxxxxxx>
> Cc: linux-media@xxxxxxxxxxxxxxx
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> ---
> drivers/media/platform/exynos4-is/fimc-is.c | 1 +
> drivers/media/platform/exynos4-is/media-dev.c | 1 +
Huh? This patch changes exynos4 as well, not just xilinx.
Please split this up into two patches, one for each driver.
> drivers/media/platform/xilinx/xilinx-vipp.c | 8 +++++---
> 3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
> index 02da0b0..25df4c6 100644
> --- a/drivers/media/platform/exynos4-is/fimc-is.c
> +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> @@ -809,6 +809,7 @@ static int fimc_is_probe(struct platform_device *pdev)
> return -ENODEV;
>
> is->pmu_regs = of_iomap(node, 0);
> + of_node_put(node);
> if (!is->pmu_regs)
> return -ENOMEM;
>
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 463f2d8..a31dacf 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -450,6 +450,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
> else
> pd->fimc_bus_type = pd->sensor_bus_type;
>
> + of_node_put(np);
> if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor))) {
> of_node_put(rem);
> return -EINVAL;
> diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
> index edce040..307717c 100644
> --- a/drivers/media/platform/xilinx/xilinx-vipp.c
> +++ b/drivers/media/platform/xilinx/xilinx-vipp.c
> @@ -472,7 +472,7 @@ static int xvip_graph_dma_init(struct xvip_composite_device *xdev)
> {
> struct device_node *ports;
> struct device_node *port;
> - int ret;
> + int ret = 0;
>
> ports = of_get_child_by_name(xdev->dev->of_node, "ports");
> if (ports == NULL) {
> @@ -484,11 +484,13 @@ 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);
> - return ret;
> + goto out_put_node;
Just do a break here,
> }
> }
>
> - return 0;
> +out_put_node:
and drop this label.
> + of_node_put(ports);
> + return ret;
> }
>
> static void xvip_graph_cleanup(struct xvip_composite_device *xdev)
>
Regards,
Hans