Re: [PATCH 5/5] cpumask: fix comment of cpumask_xxx

From: Jason A. Donenfeld
Date: Tue Mar 07 2023 - 12:58:18 EST


Hi Linus,

On Mon, Mar 6, 2023 at 10:28 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> I'm looking at wg_cpumask_next_online(), and this:
>
> while (unlikely(!cpumask_test_cpu(cpu, cpu_online_mask)))
> cpu = cpumask_next(cpu, cpu_online_mask) % nr_cpumask_bits;
>
> seems very dodgy indeed. I'm not convinced it might not cause an endless loop.

Indeed this code is crap and wrong in multiple ways. I can probably
simplify to something like

static inline int wg_cpumask_next_online(int *last_cpu)
{
int cpu = cpumask_next(*last_cpu, cpu_online_mask);
if (cpu >= nr_cpu_ids)
cpumask_first(cpu_online_mask);

as you suggested, which is indeed a lot more straightforward.

I'll get this all cleaned up.

Jason