lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0h7CeO+vG4BVcdc=XxcWMRY+OmhrWxtrAS59T-uK1KDOw@mail.gmail.com>
Date: Wed, 2 Jul 2025 20:27:21 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Yury Norov <yury.norov@...il.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Daniel Lezcano <daniel.lezcano@...aro.org>, 
	linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] cpuidle: dt: fix opencoded for_each_cpu() in idle_state_valid()

On Wed, Jun 4, 2025 at 11:39 PM Yury Norov <yury.norov@...il.com> wrote:
>
> From: Yury Norov [NVIDIA] <yury.norov@...il.com>
>
> The function opencodes the for_each_cpu_from() by using an open for-loop.
> Fix that in sake of readability.
>
> While there, drop the 'valid' variable as it's pretty useless here.
>
> Signed-off-by: Yury Norov [NVIDIA] <yury.norov@...il.com>
> ---
>  drivers/cpuidle/dt_idle_states.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c
> index 97feb7d8fb23..558d49838990 100644
> --- a/drivers/cpuidle/dt_idle_states.c
> +++ b/drivers/cpuidle/dt_idle_states.c
> @@ -98,7 +98,6 @@ static bool idle_state_valid(struct device_node *state_node, unsigned int idx,
>  {
>         int cpu;
>         struct device_node *cpu_node, *curr_state_node;
> -       bool valid = true;
>
>         /*
>          * Compare idle state phandles for index idx on all CPUs in the
> @@ -107,20 +106,17 @@ static bool idle_state_valid(struct device_node *state_node, unsigned int idx,
>          * retrieved from. If a mismatch is found bail out straight
>          * away since we certainly hit a firmware misconfiguration.
>          */
> -       for (cpu = cpumask_next(cpumask_first(cpumask), cpumask);
> -            cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpumask)) {
> +       cpu = cpumask_first(cpumask) + 1;

Doing

cpu = cpumask_next(cpumask_first(cpumask), cpumask);

here might save a few iterations for sparse cpumasks.

> +       for_each_cpu_from(cpu, cpumask) {
>                 cpu_node = of_cpu_device_node_get(cpu);
>                 curr_state_node = of_get_cpu_state_node(cpu_node, idx);
> -               if (state_node != curr_state_node)
> -                       valid = false;
> -
>                 of_node_put(curr_state_node);
>                 of_node_put(cpu_node);
> -               if (!valid)
> -                       break;
> +               if (state_node != curr_state_node)
> +                       return false;
>         }
>
> -       return valid;
> +       return true;
>  }
>
>  /**
> --
> 2.43.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ