* [PATCH 0/3] fix leaked of_node references in drivers/media
@ 2019-06-28 3:01 Wen Yang
2019-06-28 3:01 ` [PATCH 1/3] media: xilinx: fix leaked of_node references Wen Yang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Wen Yang @ 2019-06-28 3:01 UTC (permalink / raw)
To: linux-kernel
Cc: wang.yi59, Wen Yang, Mauro Carvalho Chehab, Hans Verkuil,
Laurent Pinchart, Philipp Zabel, Stanimir Varbanov, linux-media
The call to of_get_cpu_node/of_find_compatible_node/of_parse_phandle...
returns a node pointer with refcount incremented thus it must be
explicitly decremented after the last usage.
We developed a coccinelle SmPL to detect drivers/media/ code and
found some issues.
This patch series fixes those issues.
Wen Yang (3):
media: xilinx: fix leaked of_node references
media: exynos4-is: fix leaked of_node references
media: ti-vpe: fix leaked of_node references
drivers/media/platform/exynos4-is/fimc-is.c | 1 +
drivers/media/platform/exynos4-is/media-dev.c | 2 ++
drivers/media/platform/ti-vpe/cal.c | 1 +
drivers/media/platform/xilinx/xilinx-tpg.c | 18 +++++++++++++-----
drivers/media/platform/xilinx/xilinx-vipp.c | 8 +++++---
5 files changed, 22 insertions(+), 8 deletions(-)
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Stanimir Varbanov <stanimir.varbanov@linaro.org>
Cc: linux-media@vger.kernel.org
--
2.9.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] media: xilinx: fix leaked of_node references
2019-06-28 3:01 [PATCH 0/3] fix leaked of_node references in drivers/media Wen Yang
@ 2019-06-28 3:01 ` Wen Yang
2019-06-28 12:45 ` Markus Elfring
2019-06-28 3:01 ` [PATCH 2/3] media: exynos4-is: " Wen Yang
2019-06-28 3:01 ` [PATCH 3/3] media: ti-vpe: " Wen Yang
2 siblings, 1 reply; 5+ messages in thread
From: Wen Yang @ 2019-06-28 3:01 UTC (permalink / raw)
To: linux-kernel
Cc: wang.yi59, Wen Yang, Patrice Chotard, Hyun Kwon,
Laurent Pinchart, Mauro Carvalho Chehab, Michal Simek,
linux-media, linux-arm-kernel
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.
drivers/media/platform/xilinx/xilinx-tpg.c:732:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 717, but without a corresponding object release within this function.
drivers/media/platform/xilinx/xilinx-tpg.c:741:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 717, but without a corresponding object release within this function.
drivers/media/platform/xilinx/xilinx-tpg.c:757:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 717, but without a corresponding object release within this function.
drivers/media/platform/xilinx/xilinx-tpg.c:764:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 717, but without a corresponding object release within this function.
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: Hyun Kwon <hyun.kwon@xilinx.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: linux-media@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
drivers/media/platform/xilinx/xilinx-tpg.c | 18 +++++++++++++-----
drivers/media/platform/xilinx/xilinx-vipp.c | 8 +++++---
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/drivers/media/platform/xilinx/xilinx-tpg.c b/drivers/media/platform/xilinx/xilinx-tpg.c
index ed01bed..e71d022 100644
--- a/drivers/media/platform/xilinx/xilinx-tpg.c
+++ b/drivers/media/platform/xilinx/xilinx-tpg.c
@@ -713,10 +713,13 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
struct device_node *port;
unsigned int nports = 0;
bool has_endpoint = false;
+ int ret = 0;
ports = of_get_child_by_name(node, "ports");
- if (ports == NULL)
+ if (ports == NULL) {
ports = node;
+ of_node_get(ports);
+ }
for_each_child_of_node(ports, port) {
const struct xvip_video_format *format;
@@ -729,7 +732,8 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
if (IS_ERR(format)) {
dev_err(dev, "invalid format in DT");
of_node_put(port);
- return PTR_ERR(format);
+ ret = PTR_ERR(format);
+ goto out_put_node;
}
/* Get and check the format description */
@@ -738,7 +742,8 @@ 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);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_put_node;
}
if (nports == 0) {
@@ -754,14 +759,17 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
if (nports != 1 && nports != 2) {
dev_err(dev, "invalid number of ports %u\n", nports);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_put_node;
}
xtpg->npads = nports;
if (nports == 2 && has_endpoint)
xtpg->has_input = true;
- return 0;
+out_put_node:
+ of_node_put(ports);
+ return ret;
}
static int xtpg_probe(struct platform_device *pdev)
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;
}
}
- return 0;
+out_put_node:
+ of_node_put(ports);
+ return ret;
}
static void xvip_graph_cleanup(struct xvip_composite_device *xdev)
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] media: exynos4-is: fix leaked of_node references
2019-06-28 3:01 [PATCH 0/3] fix leaked of_node references in drivers/media Wen Yang
2019-06-28 3:01 ` [PATCH 1/3] media: xilinx: fix leaked of_node references Wen Yang
@ 2019-06-28 3:01 ` Wen Yang
2019-06-28 3:01 ` [PATCH 3/3] media: ti-vpe: " Wen Yang
2 siblings, 0 replies; 5+ messages in thread
From: Wen Yang @ 2019-06-28 3:01 UTC (permalink / raw)
To: linux-kernel
Cc: wang.yi59, Wen Yang, Kyungmin Park, Sylwester Nawrocki,
Mauro Carvalho Chehab, Kukjin Kim, Krzysztof Kozlowski,
linux-media, linux-arm-kernel, linux-samsung-soc
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/exynos4-is/fimc-is.c:813:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 807, but without a corresponding object release within this function.
drivers/media/platform/exynos4-is/fimc-is.c:870:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 807, but without a corresponding object release within this function.
drivers/media/platform/exynos4-is/fimc-is.c:885:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 807, but without a corresponding object release within this function.
drivers/media/platform/exynos4-is/media-dev.c:545:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 541, but without a corresponding object release within this function.
drivers/media/platform/exynos4-is/media-dev.c:528:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 499, but without a corresponding object release within this function.
drivers/media/platform/exynos4-is/media-dev.c:534:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 499, but without a corresponding object release within this function.
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: linux-media@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/media/platform/exynos4-is/fimc-is.c | 1 +
drivers/media/platform/exynos4-is/media-dev.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
index e043d55..b7cc8e6 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -806,6 +806,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 d53427a..a838189 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -501,6 +501,7 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
continue;
ret = fimc_md_parse_port_node(fmd, port, index);
+ of_node_put(port);
if (ret < 0) {
of_node_put(node);
goto cleanup;
@@ -542,6 +543,7 @@ static int __of_get_csis_id(struct device_node *np)
if (!np)
return -EINVAL;
of_property_read_u32(np, "reg", ®);
+ of_node_put(np);
return reg - FIMC_INPUT_MIPI_CSI2_0;
}
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] media: ti-vpe: fix leaked of_node references
2019-06-28 3:01 [PATCH 0/3] fix leaked of_node references in drivers/media Wen Yang
2019-06-28 3:01 ` [PATCH 1/3] media: xilinx: fix leaked of_node references Wen Yang
2019-06-28 3:01 ` [PATCH 2/3] media: exynos4-is: " Wen Yang
@ 2019-06-28 3:01 ` Wen Yang
2 siblings, 0 replies; 5+ messages in thread
From: Wen Yang @ 2019-06-28 3:01 UTC (permalink / raw)
To: linux-kernel
Cc: wang.yi59, Wen Yang, Benoit Parrot, Mauro Carvalho Chehab, linux-media
The call to of_get_parent 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/ti-vpe/cal.c:1621:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1607, but without a corresponding object release within this function.
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Benoit Parrot <bparrot@ti.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/media/platform/ti-vpe/cal.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 9e86d761..8e19974 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1613,6 +1613,7 @@ of_get_next_port(const struct device_node *parent,
}
prev = port;
} while (!of_node_name_eq(port, "port"));
+ of_node_put(ports);
}
return port;
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] media: xilinx: fix leaked of_node references
2019-06-28 3:01 ` [PATCH 1/3] media: xilinx: fix leaked of_node references Wen Yang
@ 2019-06-28 12:45 ` Markus Elfring
0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2019-06-28 12:45 UTC (permalink / raw)
To: Wen Yang, linux-arm-kernel, linux-media
Cc: Hyun Kwon, Laurent Pinchart, linux-kernel, Mauro Carvalho Chehab,
Michal Simek, Patrice Chotard, Yi Wang
> +++ b/drivers/media/platform/xilinx/xilinx-tpg.c
> @@ -713,10 +713,13 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
> struct device_node *port;
> unsigned int nports = 0;
> bool has_endpoint = false;
> + int ret = 0;
>
> ports = of_get_child_by_name(node, "ports");
> - if (ports == NULL)
> + if (ports == NULL) {
The script “checkpatch.pl” can point information out like “Comparison to NULL
could be written …”.
Thus fix the affected source code place.
+ if (!ports) {
> ports = node;
> + of_node_get(ports);
> + }
>
> for_each_child_of_node(ports, port) {
> const struct xvip_video_format *format;
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-28 12:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28 3:01 [PATCH 0/3] fix leaked of_node references in drivers/media Wen Yang
2019-06-28 3:01 ` [PATCH 1/3] media: xilinx: fix leaked of_node references Wen Yang
2019-06-28 12:45 ` Markus Elfring
2019-06-28 3:01 ` [PATCH 2/3] media: exynos4-is: " Wen Yang
2019-06-28 3:01 ` [PATCH 3/3] media: ti-vpe: " Wen Yang
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).