linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
@ 2025-09-03 13:37 Miaoqian Lin
  2025-09-03 15:09 ` Geert Uytterhoeven
  2025-09-03 17:14 ` Fabrizio Castro
  0 siblings, 2 replies; 4+ messages in thread
From: Miaoqian Lin @ 2025-09-03 13:37 UTC (permalink / raw)
  To: Fabrizio Castro, Mauro Carvalho Chehab, Geert Uytterhoeven,
	Magnus Damm, Ramesh Shanmugasundaram, Hans Verkuil, linux-media,
	linux-renesas-soc, linux-kernel
  Cc: linmq006, stable

The function calls of_parse_phandle() which returns
a device node with an incremented reference count. When the bonded device
is not available, the function
returns NULL without releasing the reference, causing a reference leak.

Add of_node_put(np) to release the device node reference.
The of_node_put function handles NULL pointers.

Found through static analysis by reviewing the doc of of_parse_phandle()
and cross-checking its usage patterns across the codebase.

Fixes: 7625ee981af1 ("[media] media: platform: rcar_drif: Add DRIF support")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/media/platform/renesas/rcar_drif.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/renesas/rcar_drif.c b/drivers/media/platform/renesas/rcar_drif.c
index fc8b6bbef793..c5d676eb1091 100644
--- a/drivers/media/platform/renesas/rcar_drif.c
+++ b/drivers/media/platform/renesas/rcar_drif.c
@@ -1246,6 +1246,7 @@ static struct device_node *rcar_drif_bond_enabled(struct platform_device *p)
 	if (np && of_device_is_available(np))
 		return np;
 
+	of_node_put(np);
 	return NULL;
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
  2025-09-03 13:37 [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled Miaoqian Lin
@ 2025-09-03 15:09 ` Geert Uytterhoeven
  2025-09-03 16:45   ` Markus Elfring
  2025-09-03 17:14 ` Fabrizio Castro
  1 sibling, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2025-09-03 15:09 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Fabrizio Castro, Mauro Carvalho Chehab, Magnus Damm,
	Ramesh Shanmugasundaram, Hans Verkuil, linux-media,
	linux-renesas-soc, linux-kernel, stable

On Wed, 3 Sept 2025 at 15:37, Miaoqian Lin <linmq006@gmail.com> wrote:
> The function calls of_parse_phandle() which returns
> a device node with an incremented reference count. When the bonded device
> is not available, the function
> returns NULL without releasing the reference, causing a reference leak.
>
> Add of_node_put(np) to release the device node reference.
> The of_node_put function handles NULL pointers.
>
> Found through static analysis by reviewing the doc of of_parse_phandle()
> and cross-checking its usage patterns across the codebase.
>
> Fixes: 7625ee981af1 ("[media] media: platform: rcar_drif: Add DRIF support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Note that this is a duplicate of "[PATCH] media: rcar_drif: Fix an OF
node leak in rcar_drif_bond_enabled()", which was never applied.

[1] https://lore.kernel.org/20250105111050.3859712-1-joe@pf.is.s.u-tokyo.ac.jp

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
  2025-09-03 15:09 ` Geert Uytterhoeven
@ 2025-09-03 16:45   ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-09-03 16:45 UTC (permalink / raw)
  To: Geert Uytterhoeven, Miaoqian Lin, linux-renesas-soc, linux-media
  Cc: stable, LKML, Fabrizio Castro, Hans Verkuil, Joe Hattori,
	Magnus Damm, Mauro Carvalho Chehab, Ramesh Shanmugasundaram

> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Are any description details still improvable?


> Note that this is a duplicate of "[PATCH] media: rcar_drif: Fix an OF
> node leak in rcar_drif_bond_enabled()", which was never applied.
> 
> [1] https://lore.kernel.org/20250105111050.3859712-1-joe@pf.is.s.u-tokyo.ac.jp

Would it be nicer (in principle) to integrate this patch finally?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
  2025-09-03 13:37 [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled Miaoqian Lin
  2025-09-03 15:09 ` Geert Uytterhoeven
@ 2025-09-03 17:14 ` Fabrizio Castro
  1 sibling, 0 replies; 4+ messages in thread
From: Fabrizio Castro @ 2025-09-03 17:14 UTC (permalink / raw)
  To: Miaoqian Lin, Mauro Carvalho Chehab, Geert Uytterhoeven,
	magnus.damm, Ramesh Shanmugasundaram, Hans Verkuil,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
  Cc: stable@vger.kernel.org

> From: Miaoqian Lin <linmq006@gmail.com>
> Sent: 03 September 2025 14:37
> To: Fabrizio Castro <fabrizio.castro.jz@renesas.com>; Mauro Carvalho Chehab <mchehab@kernel.org>; Geert
> Uytterhoeven <geert+renesas@glider.be>; magnus.damm <magnus.damm@gmail.com>; Ramesh Shanmugasundaram
> <ramesh.shanmugasundaram@bp.renesas.com>; Hans Verkuil <hverkuil@kernel.org>; linux-
> media@vger.kernel.org; linux-renesas-soc@vger.kernel.org; linux-kernel@vger.kernel.org
> Cc: linmq006@gmail.com; stable@vger.kernel.org
> Subject: [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
> 
> The function calls of_parse_phandle() which returns
> a device node with an incremented reference count. When the bonded device
> is not available, the function
> returns NULL without releasing the reference, causing a reference leak.
> 
> Add of_node_put(np) to release the device node reference.
> The of_node_put function handles NULL pointers.
> 
> Found through static analysis by reviewing the doc of of_parse_phandle()
> and cross-checking its usage patterns across the codebase.
> 
> Fixes: 7625ee981af1 ("[media] media: platform: rcar_drif: Add DRIF support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>

> ---
>  drivers/media/platform/renesas/rcar_drif.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/media/platform/renesas/rcar_drif.c b/drivers/media/platform/renesas/rcar_drif.c
> index fc8b6bbef793..c5d676eb1091 100644
> --- a/drivers/media/platform/renesas/rcar_drif.c
> +++ b/drivers/media/platform/renesas/rcar_drif.c
> @@ -1246,6 +1246,7 @@ static struct device_node *rcar_drif_bond_enabled(struct platform_device *p)
>  	if (np && of_device_is_available(np))
>  		return np;
> 
> +	of_node_put(np);
>  	return NULL;
>  }
> 
> --
> 2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-03 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 13:37 [PATCH] media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled Miaoqian Lin
2025-09-03 15:09 ` Geert Uytterhoeven
2025-09-03 16:45   ` Markus Elfring
2025-09-03 17:14 ` Fabrizio Castro

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).