# Re: \[PATCH 3/5\] scsi: lpfc: fix lpfc\_cpu\_affinity\_check() if no further cpus set

- From: Linus Torvalds \<torvalds@linux-foundation.org\>
- Date: 2023-03-06 18:48:31 
- List: netdev
- Page: https://ratatoskr.run/netdev/2023/03/2122202
- Thread: https://ratatoskr.run/netdev/2023/03/2121900/t.md

```text
On Mon, Mar 6, 2023 at 8:07 AM Vernon Yang [ref] wrote:
>
> -                               if (new_cpu == nr_cpumask_bits)
> +                               if (new_cpu >= nr_cpumask_bits)

This all should use "nr_cpu_ids", not "nr_cpumask_bits".

But I really suspect that it should all be rewritten to not do that
thing over and over, but just use a helper function for it.

  int lpfc_next_present_cpu(int n, int alternate)
  {
        n = cpumask_next(n, cpu_present_mask);
        if (n >= nr_cpu_ids)
                n = alternate;
        return n;
  }

and then you could just use

        start_cpu = lpfc_next_present_cpu(new_cpu, first_cpu);

or similar.

              Linus

PS. We "kind of" already have a helper function for this:
cpumask_next_wrap(). But it's really meant for a different pattern
entirely, so let's not confuse things.
```
