Skip to contentSkip to conversation

cache: starfive: fix device node leak in starlink_cache_init()

PATCH Applied Felix Gu 3 participants 3 messages Jan 30 – Feb 6

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 cache: starfive: fix device node leak in starlink_cache_init()

of_find_matching_node() returns a device_node with refcount incremented.

Use __free(device_node) attribute to automatically call of_node_put() when the variable goes out of scope, preventing the refcount leak.

Fixes cabff60ca77d ("cache: Add StarFive StarLink cache management")
---
 drivers/cache/starfive_starlink_cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cache/starfive_starlink_cache.c +2 -2
index 24c7d078ca22..3a25d2d7c70c 100644
@@ -102,11 +102,11 @@ static const struct of_device_id starlink_cache_ids[] = {
 
 static int __init starlink_cache_init(void)
 {
-	struct device_node *np;
 	u32 block_size;
 	int ret;
 
-	np = of_find_matching_node(NULL, starlink_cache_ids);
+	struct device_node *np __free(device_node) =
+		of_find_matching_node(NULL, starlink_cache_ids);
 	if (!of_device_is_available(np))
 		return -ENODEV;
 

---
base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215
change-id: 20260131-starlink-b23bf5ac7323

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Sat, 31 Jan 2026 01:13:45 +0800 Felix Gu <[email protected]> wrote:

of_find_matching_node() returns a device_node with refcount incremented.

Use __free(device_node) attribute to automatically call of_node_put() when the variable goes out of scope, preventing the refcount leak.

Fixes cabff60ca77d ("cache: Add StarFive StarLink cache management")

Indeed a leak that should be fixed and doesn't look like there can be any access to np from outside of this function, so the fix is good.

Quoted 28 lines
---
 drivers/cache/starfive_starlink_cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cache/starfive_starlink_cache.c +2 -3
index 24c7d078ca22..3a25d2d7c70c 100644
@@ -102,11 +102,11 @@ static const struct of_device_id starlink_cache_ids[] = {
 
 static int __init starlink_cache_init(void)
 {
-	struct device_node *np;
 	u32 block_size;
 	int ret;
 
-	np = of_find_matching_node(NULL, starlink_cache_ids);
+	struct device_node *np __free(device_node) =
+		of_find_matching_node(NULL, starlink_cache_ids);
 	if (!of_device_is_available(np))
 		return -ENODEV;
 
 
---

base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215
change-id: 20260131-starlink-b23bf5ac7323

Best regards,

maintainer Applied
#2 lore raw
In reply to Felix Gu

From: Conor Dooley <[email protected]>

Quoted 6 lines · Felix Gu

of_find_matching_node() returns a device_node with refcount incremented.

Use __free(device_node) attribute to automatically call of_node_put() when the variable goes out of scope, preventing the refcount leak.

Applied to riscv-soc-fixes, thanks!

[1/1] cache: starfive: fix device node leak in starlink_cache_init()

      https://git.kernel.org/conor/c/3c85234b979a

Thanks,
Conor.