Skip to contentSkip to conversation

media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled

PATCH In review Miaoqian Lin 5 participants 5 messages Sep 3, 2025 – Nov 3, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/media/platform/renesas/rcar_drif.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/platform/renesas/rcar_drif.c +1 -0
index fc8b6bbef793..c5d676eb1091 100644
@@ -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;
 }
 
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Miaoqian Lin

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.

Quoted 6 lines

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

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/[email protected]

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#3 lore raw
In reply to Geert Uytterhoeven
Quoted 16 lines · Geert Uytterhoeven
Quoted 8 lines · Miaoqian Lin

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.

Quoted 6 lines

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")
Quoted 6 lines

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/[email protected]

Ah, that patch was never CC-ed to linux-media, so never ended up in our patchwork instance. That's why that wasn't picked up.

I'll take this patch instead.

Regards,

Hans

Quoted 5 lines

Gr{oetje,eeting}s,

Geert

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Miaoqian Lin
Quoted 17 lines

From: Miaoqian Lin <[email protected]>
Sent: 03 September 2025 14:37
To: Fabrizio Castro <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Geert Uytterhoeven <[email protected]>; magnus.damm <[email protected]>; Ramesh Shanmugasundaram <[email protected]>; Hans Verkuil <[email protected]>; linux- [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
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.

Quoted 6 lines

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")
Quoted 18 lines
---
 drivers/media/platform/renesas/rcar_drif.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/platform/renesas/rcar_drif.c +1 -1
index fc8b6bbef793..c5d676eb1091 100644
@@ -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