media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
Subsystems (4)
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.
--- drivers/media/platform/renesas/rcar_drif.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/renesas/rcar_drif.c +1 -0
@@ -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
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. Theof_node_putfunction 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")Signed-off-by Miaoqian Lin <[email protected]>
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
Quoted 1 line
Reviewed-by Geert Uytterhoeven <[email protected]>
Are any description details still improvable?
Quoted 4 lines
Note that this is a duplicate of "[PATCH] media:
rcar_drif: Fix an OF node leak inrcar_drif_bond_enabled()", which was never applied.
Would it be nicer (in principle) to integrate this patch finally?
Regards,
Markus
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. Theof_node_putfunction 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")Signed-off-by Miaoqian Lin <[email protected]>
Quoted 6 lines
Reviewed-by Geert Uytterhoeven <[email protected]>Note that this is a duplicate of "[PATCH] media:
rcar_drif: Fix an OF node leak inrcar_drif_bond_enabled()", which was never applied.
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
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 inrcar_drif_bond_enabledThe 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. Theof_node_putfunction 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")Signed-off-by Miaoqian Lin <[email protected]>
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@@ -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