[PATCH] media: samsung: exynos4-is: Drop extra of_node_put() on endpoint

Zijie Zhao via B4 Relay devnull+zzjas98.gmail.com at kernel.org
Tue Dec 1 14:43:34 PST 2026


From: Zijie Zhao <zzjas98 at gmail.com>

fimc_md_parse_port_node() iterates over the endpoint nodes of a port
with for_each_child_of_node_scoped() and passes each one to
fimc_md_parse_one_endpoint(). The reference on the endpoint belongs to
the iterator: it is dropped by of_get_next_child() when the loop
advances, or by the scoped cleanup when the loop exits early.

fimc_md_parse_one_endpoint() also calls of_node_put() on the endpoint
on every return path, so probe drops one reference more than it took
for each parsed endpoint. With CONFIG_OF_DYNAMIC this can release an
endpoint node that is still attached to the tree, which
of_node_release() reports as a bad of_node_put(), and leaves the
node's refcount at zero while it is still in use.

The helper started doing this when it was split out of
fimc_md_parse_port_node(), which until then took its own reference on
the endpoint with of_get_next_child(), and kept the matching puts.

Drop the of_node_put() calls from fimc_md_parse_one_endpoint() and let
the iterator manage the reference.

Found by a static analysis tool.

The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Fixes: 18174117ba18 ("media: exynos4-is: Add support for multiple sensors on one port")
Signed-off-by: Zijie Zhao <zzjas98 at gmail.com>
---
An alternative fix would be to take an extra reference with of_node_get() in
the caller and keep the helper's puts. Removing the puts was chosen because
the helper never acquires ep and the scoped iterator already owns it.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
  drivers/media/platform/samsung/exynos4-is/media-dev.o; no new
  warnings.
- checkpatch.pl --strict: no errors or warnings.
---
 drivers/media/platform/samsung/exynos4-is/media-dev.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/samsung/exynos4-is/media-dev.c b/drivers/media/platform/samsung/exynos4-is/media-dev.c
index 2e08c4435859..5a1d945580b8 100644
--- a/drivers/media/platform/samsung/exynos4-is/media-dev.c
+++ b/drivers/media/platform/samsung/exynos4-is/media-dev.c
@@ -405,15 +405,11 @@ static int fimc_md_parse_one_endpoint(struct fimc_md *fmd,
 	int ret;
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &endpoint);
-	if (ret) {
-		of_node_put(ep);
+	if (ret)
 		return ret;
-	}
 
-	if (WARN_ON(endpoint.base.port == 0) || index >= FIMC_MAX_SENSORS) {
-		of_node_put(ep);
+	if (WARN_ON(endpoint.base.port == 0) || index >= FIMC_MAX_SENSORS)
 		return -EINVAL;
-	}
 
 	pd->mux_id = (endpoint.base.port - 1) & 0x1;
 
@@ -421,7 +417,6 @@ static int fimc_md_parse_one_endpoint(struct fimc_md *fmd,
 	if (rem == NULL) {
 		v4l2_info(&fmd->v4l2_dev, "Remote device at %pOF not found\n",
 							ep);
-		of_node_put(ep);
 		return 0;
 	}
 
@@ -458,17 +453,13 @@ static int fimc_md_parse_one_endpoint(struct fimc_md *fmd,
 		pd->fimc_bus_type = pd->sensor_bus_type;
 	of_node_put(np);
 
-	if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor))) {
-		of_node_put(ep);
+	if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor)))
 		return -EINVAL;
-	}
 
 	asd = v4l2_async_nf_add_fwnode_remote(&fmd->subdev_notifier,
 					      of_fwnode_handle(ep),
 					      struct v4l2_async_connection);
 
-	of_node_put(ep);
-
 	if (IS_ERR(asd))
 		return PTR_ERR(asd);
 

---
base-commit: b4e3c4b6a36fd76f57bf3e48638f68ddecc54ba4
change-id: 20261201-kbug-l561-exynos4-is-6a89abd9cbd3

Best regards,
--  
Zijie Zhao <zzjas98 at gmail.com>





More information about the linux-arm-kernel mailing list