public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cache: starfive: fix device node leak in starlink_cache_init()
@ 2026-01-30 17:13 Felix Gu
  2026-01-30 17:28 ` Jonathan Cameron
  2026-02-06 20:28 ` Conor Dooley
  0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-01-30 17:13 UTC (permalink / raw)
  To: Conor Dooley, Jonathan Cameron, Joshua Yeong
  Cc: Conor Dooley, linux-kernel, 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.

Fixes: cabff60ca77d ("cache: Add StarFive StarLink cache management")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/cache/starfive_starlink_cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cache/starfive_starlink_cache.c b/drivers/cache/starfive_starlink_cache.c
index 24c7d078ca22..3a25d2d7c70c 100644
--- a/drivers/cache/starfive_starlink_cache.c
+++ b/drivers/cache/starfive_starlink_cache.c
@@ -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,
-- 
Felix Gu <ustc.gu@gmail.com>


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

* Re: [PATCH] cache: starfive: fix device node leak in starlink_cache_init()
  2026-01-30 17:13 [PATCH] cache: starfive: fix device node leak in starlink_cache_init() Felix Gu
@ 2026-01-30 17:28 ` Jonathan Cameron
  2026-02-06 20:28 ` Conor Dooley
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-01-30 17:28 UTC (permalink / raw)
  To: Felix Gu; +Cc: Conor Dooley, Joshua Yeong, Conor Dooley, linux-kernel

On Sat, 31 Jan 2026 01:13:45 +0800
Felix Gu <ustc.gu@gmail.com> 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")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

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.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>


> ---
>  drivers/cache/starfive_starlink_cache.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cache/starfive_starlink_cache.c b/drivers/cache/starfive_starlink_cache.c
> index 24c7d078ca22..3a25d2d7c70c 100644
> --- a/drivers/cache/starfive_starlink_cache.c
> +++ b/drivers/cache/starfive_starlink_cache.c
> @@ -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,


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

* Re: [PATCH] cache: starfive: fix device node leak in starlink_cache_init()
  2026-01-30 17:13 [PATCH] cache: starfive: fix device node leak in starlink_cache_init() Felix Gu
  2026-01-30 17:28 ` Jonathan Cameron
@ 2026-02-06 20:28 ` Conor Dooley
  1 sibling, 0 replies; 3+ messages in thread
From: Conor Dooley @ 2026-02-06 20:28 UTC (permalink / raw)
  To: linux-riscv, Conor Dooley, Jonathan Cameron, Joshua Yeong,
	Felix Gu
  Cc: Conor Dooley, Daire McNamara, Rob Herring, Krzysztof Kozlowski,
	devicetree, linux-kernel

From: Conor Dooley <conor.dooley@microchip.com>

On Sat, 31 Jan 2026 01:13:45 +0800, Felix Gu 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.
> 
> 

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.

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

end of thread, other threads:[~2026-02-06 20:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30 17:13 [PATCH] cache: starfive: fix device node leak in starlink_cache_init() Felix Gu
2026-01-30 17:28 ` Jonathan Cameron
2026-02-06 20:28 ` Conor Dooley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox