[PATCH] drm/tegra: dc: Fix device node reference leak in tegra_dc_has_output()

Felix Gu posted 1 patch 1 week, 3 days ago
drivers/gpu/drm/tegra/dc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] drm/tegra: dc: Fix device node reference leak in tegra_dc_has_output()
Posted by Felix Gu 1 week, 3 days ago
The of_for_each_phandle() macro increments the reference count of the
device node it iterates over. If the loop exits early, the reference must
be released manually.

In tegra_dc_has_output(), the function returns true immediately when a
match is found, failing to release the current node's reference.

Fix this by adding a call to of_node_put() before returning from the loop.

Fixes: c57997bce423 ("drm/tegra: sor: Add Tegra186 support")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/gpu/drm/tegra/dc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 01e9d5011dd8..9bf6c008a5ea 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -101,8 +101,10 @@ bool tegra_dc_has_output(struct tegra_dc *dc, struct device *dev)
 	int err;
 
 	of_for_each_phandle(&it, err, np, "nvidia,outputs", NULL, 0)
-		if (it.node == dev->of_node)
+		if (it.node == dev->of_node) {
+			of_node_put(it.node);
 			return true;
+		}
 
 	return false;
 }

---
base-commit: 615aad0f61e0c7a898184a394dc895c610100d4f
change-id: 20260127-dc-e396ab5384da

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>
Re: [PATCH] drm/tegra: dc: Fix device node reference leak in tegra_dc_has_output()
Posted by Mikko Perttunen 1 day, 1 hour ago
On Wednesday, January 28, 2026 1:43 AM Felix Gu wrote:
> The of_for_each_phandle() macro increments the reference count of the
> device node it iterates over. If the loop exits early, the reference must
> be released manually.
> 
> In tegra_dc_has_output(), the function returns true immediately when a
> match is found, failing to release the current node's reference.
> 
> Fix this by adding a call to of_node_put() before returning from the loop.
> 
> Fixes: c57997bce423 ("drm/tegra: sor: Add Tegra186 support")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/gpu/drm/tegra/dc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
> index 01e9d5011dd8..9bf6c008a5ea 100644
> --- a/drivers/gpu/drm/tegra/dc.c
> +++ b/drivers/gpu/drm/tegra/dc.c
> @@ -101,8 +101,10 @@ bool tegra_dc_has_output(struct tegra_dc *dc, struct device *dev)
>  	int err;
>  
>  	of_for_each_phandle(&it, err, np, "nvidia,outputs", NULL, 0)
> -		if (it.node == dev->of_node)
> +		if (it.node == dev->of_node) {
> +			of_node_put(it.node);
>  			return true;
> +		}
>  
>  	return false;
>  }
> 
> ---
> base-commit: 615aad0f61e0c7a898184a394dc895c610100d4f
> change-id: 20260127-dc-e396ab5384da
> 
> Best regards,
> -- 
> Felix Gu <ustc.gu@gmail.com>
> 
> 

Acked-by: Mikko Perttunen <mperttunen@nvidia.com>