mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
@ 2024-11-15 23:32 Javier Carrasco
  2024-12-05 14:40 ` Alexandre Ghiti
  2025-01-09 16:16 ` patchwork-bot+linux-riscv
  0 siblings, 2 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-11-15 23:32 UTC (permalink / raw)
  To: Anup Patel, Rafael J. Wysocki, Daniel Lezcano, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Atish Patra
  Cc: Palmer Dabbelt, linux-pm, linux-riscv, linux-kernel,
	Andrew Jones, Javier Carrasco

The 'np' device_node is initialized via of_cpu_device_node_get(), which
requires explicit calls to of_node_put() when it is no longer required
to avoid leaking the resource.

Instead of adding the missing calls to of_node_put() in all execution
paths, use the cleanup attribute for 'np' by means of the __free()
macro, which automatically calls of_node_put() when the variable goes
out of scope. Given that 'np' is only used within the
for_each_possible_cpu(), reduce its scope to release the nood after
every iteration of the loop.

Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver")
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v3:
- Unwrap line (100 char width).
- Link to v2: https://lore.kernel.org/r/20241031-cpuidle-riscv-sbi-cleanup-v2-1-aae62d383118@gmail.com

Changes in v2:
- Squash patches for mainline solution without intermediate steps.
- Link to v1: https://lore.kernel.org/r/20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com
---
 drivers/cpuidle/cpuidle-riscv-sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index 14462c092039..0c92a628bbd4 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -504,12 +504,12 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
 	int cpu, ret;
 	struct cpuidle_driver *drv;
 	struct cpuidle_device *dev;
-	struct device_node *np, *pds_node;
+	struct device_node *pds_node;
 
 	/* Detect OSI support based on CPU DT nodes */
 	sbi_cpuidle_use_osi = true;
 	for_each_possible_cpu(cpu) {
-		np = of_cpu_device_node_get(cpu);
+		struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu);
 		if (np &&
 		    of_property_present(np, "power-domains") &&
 		    of_property_present(np, "power-domain-names")) {

---
base-commit: 744cf71b8bdfcdd77aaf58395e068b7457634b2c
change-id: 20241029-cpuidle-riscv-sbi-cleanup-e9b3cb96e16d

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


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

* Re: [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
  2024-11-15 23:32 [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu Javier Carrasco
@ 2024-12-05 14:40 ` Alexandre Ghiti
  2024-12-05 15:12   ` Anup Patel
  2025-01-09 16:16 ` patchwork-bot+linux-riscv
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Ghiti @ 2024-12-05 14:40 UTC (permalink / raw)
  To: Javier Carrasco, Anup Patel, Rafael J. Wysocki, Daniel Lezcano,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Atish Patra
  Cc: Palmer Dabbelt, linux-pm, linux-riscv, linux-kernel, Andrew Jones

Hi Anup,

On 16/11/2024 00:32, Javier Carrasco wrote:
> The 'np' device_node is initialized via of_cpu_device_node_get(), which
> requires explicit calls to of_node_put() when it is no longer required
> to avoid leaking the resource.
>
> Instead of adding the missing calls to of_node_put() in all execution
> paths, use the cleanup attribute for 'np' by means of the __free()
> macro, which automatically calls of_node_put() when the variable goes
> out of scope. Given that 'np' is only used within the
> for_each_possible_cpu(), reduce its scope to release the nood after
> every iteration of the loop.
>
> Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver")
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> Changes in v3:
> - Unwrap line (100 char width).
> - Link to v2: https://lore.kernel.org/r/20241031-cpuidle-riscv-sbi-cleanup-v2-1-aae62d383118@gmail.com
>
> Changes in v2:
> - Squash patches for mainline solution without intermediate steps.
> - Link to v1: https://lore.kernel.org/r/20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com
> ---
>   drivers/cpuidle/cpuidle-riscv-sbi.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index 14462c092039..0c92a628bbd4 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -504,12 +504,12 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
>   	int cpu, ret;
>   	struct cpuidle_driver *drv;
>   	struct cpuidle_device *dev;
> -	struct device_node *np, *pds_node;
> +	struct device_node *pds_node;
>   
>   	/* Detect OSI support based on CPU DT nodes */
>   	sbi_cpuidle_use_osi = true;
>   	for_each_possible_cpu(cpu) {
> -		np = of_cpu_device_node_get(cpu);
> +		struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu);
>   		if (np &&
>   		    of_property_present(np, "power-domains") &&
>   		    of_property_present(np, "power-domain-names")) {
>
> ---
> base-commit: 744cf71b8bdfcdd77aaf58395e068b7457634b2c
> change-id: 20241029-cpuidle-riscv-sbi-cleanup-e9b3cb96e16d
>
> Best regards,


Will you make a PR for this? Or should this go through the riscv tree?

Thanks,

Alex


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

* Re: [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
  2024-12-05 14:40 ` Alexandre Ghiti
@ 2024-12-05 15:12   ` Anup Patel
  0 siblings, 0 replies; 4+ messages in thread
From: Anup Patel @ 2024-12-05 15:12 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: Javier Carrasco, Anup Patel, Rafael J. Wysocki, Daniel Lezcano,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Atish Patra,
	Palmer Dabbelt, linux-pm, linux-riscv, linux-kernel,
	Andrew Jones

On Thu, Dec 5, 2024 at 8:10 PM Alexandre Ghiti <alex@ghiti.fr> wrote:
>
> Hi Anup,
>
> On 16/11/2024 00:32, Javier Carrasco wrote:
> > The 'np' device_node is initialized via of_cpu_device_node_get(), which
> > requires explicit calls to of_node_put() when it is no longer required
> > to avoid leaking the resource.
> >
> > Instead of adding the missing calls to of_node_put() in all execution
> > paths, use the cleanup attribute for 'np' by means of the __free()
> > macro, which automatically calls of_node_put() when the variable goes
> > out of scope. Given that 'np' is only used within the
> > for_each_possible_cpu(), reduce its scope to release the nood after
> > every iteration of the loop.
> >
> > Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver")
> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> > ---
> > Changes in v3:
> > - Unwrap line (100 char width).
> > - Link to v2: https://lore.kernel.org/r/20241031-cpuidle-riscv-sbi-cleanup-v2-1-aae62d383118@gmail.com
> >
> > Changes in v2:
> > - Squash patches for mainline solution without intermediate steps.
> > - Link to v1: https://lore.kernel.org/r/20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com
> > ---
> >   drivers/cpuidle/cpuidle-riscv-sbi.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> > index 14462c092039..0c92a628bbd4 100644
> > --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> > +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> > @@ -504,12 +504,12 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
> >       int cpu, ret;
> >       struct cpuidle_driver *drv;
> >       struct cpuidle_device *dev;
> > -     struct device_node *np, *pds_node;
> > +     struct device_node *pds_node;
> >
> >       /* Detect OSI support based on CPU DT nodes */
> >       sbi_cpuidle_use_osi = true;
> >       for_each_possible_cpu(cpu) {
> > -             np = of_cpu_device_node_get(cpu);
> > +             struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu);
> >               if (np &&
> >                   of_property_present(np, "power-domains") &&
> >                   of_property_present(np, "power-domain-names")) {
> >
> > ---
> > base-commit: 744cf71b8bdfcdd77aaf58395e068b7457634b2c
> > change-id: 20241029-cpuidle-riscv-sbi-cleanup-e9b3cb96e16d
> >
> > Best regards,
>
>
> Will you make a PR for this? Or should this go through the riscv tree?

It's not KVM related so better take it through the RISC-V tree.

Regards,
Anup

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

* Re: [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
  2024-11-15 23:32 [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu Javier Carrasco
  2024-12-05 14:40 ` Alexandre Ghiti
@ 2025-01-09 16:16 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-01-09 16:16 UTC (permalink / raw)
  To: Javier Carrasco
  Cc: linux-riscv, anup, rafael, daniel.lezcano, paul.walmsley, palmer,
	aou, atishp, palmer, linux-pm, linux-kernel, ajones

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Sat, 16 Nov 2024 00:32:39 +0100 you wrote:
> The 'np' device_node is initialized via of_cpu_device_node_get(), which
> requires explicit calls to of_node_put() when it is no longer required
> to avoid leaking the resource.
> 
> Instead of adding the missing calls to of_node_put() in all execution
> paths, use the cleanup attribute for 'np' by means of the __free()
> macro, which automatically calls of_node_put() when the variable goes
> out of scope. Given that 'np' is only used within the
> for_each_possible_cpu(), reduce its scope to release the nood after
> every iteration of the loop.
> 
> [...]

Here is the summary with links:
  - [v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
    https://git.kernel.org/riscv/c/7e25044b8045

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-01-09 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-15 23:32 [PATCH v3] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu Javier Carrasco
2024-12-05 14:40 ` Alexandre Ghiti
2024-12-05 15:12   ` Anup Patel
2025-01-09 16:16 ` patchwork-bot+linux-riscv

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

all inboxes | Powered by JetHome®