Subject: Re: [PATCH 2/2] powerpc: Few misc cpumask code refactors

From: Yury Norov <[email-masked]>
Date: Sat, 28 Mar 2026 16:27:36 -0400

On Fri, Mar 27, 2026 at 12:01:29PM +0530, Shrikanth Hegde wrote:
> A few miscellanous changes in handling cpumask api's in the order
> they appear:
> 
> - cpumask_next(cpu, mask) >= nr_cpu_ids is used to determine if
>   cpu is the last CPU. 
> 
> - cpumask_next can take -1 as valid argument. So simplify cpuinfo
>   iterator. /proc/cpuinfo shows same info with patch.
> 
> - cpumask_weight can't be more than nr_cpu_ids. So remove the pointless
>   comparison.
> 
> Signed-off-by: Shrikanth Hegde <[email-masked]>
> ---
>  arch/powerpc/kernel/setup-common.c | 7 ++-----
>  arch/powerpc/sysdev/xive/common.c  | 7 +++----
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
> index b1761909c23f..47215eab296b 100644
> --- a/arch/powerpc/kernel/setup-common.c
> +++ b/arch/powerpc/kernel/setup-common.c
> @@ -323,7 +323,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
>  	seq_putc(m, '\n');
>  
>  	/* If this is the last cpu, print the summary */
> -	if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
> +	if (cpu_id == cpumask_last(cpu_online_mask))
>  		show_cpuinfo_summary(m);
>  
>  	return 0;
> @@ -331,10 +331,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
>  
>  static void *c_start(struct seq_file *m, loff_t *pos)
>  {
> -	if (*pos == 0)	/* just in case, cpu 0 is not the first */
> -		*pos = cpumask_first(cpu_online_mask);
> -	else
> -		*pos = cpumask_next(*pos - 1, cpu_online_mask);
> +	*pos = cpumask_next(*pos - 1, cpu_online_mask);
>  	if ((*pos) < nr_cpu_ids)
>  		return (void *)(unsigned long)(*pos + 1);
>  	return NULL;
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index b6446abe29a6..91dd3b364d7d 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -548,11 +548,10 @@ static void xive_dec_target_count(int cpu)
>  static int xive_find_target_in_mask(const struct cpumask *mask,
>  				    unsigned int fuzz)
>  {
> -	int cpu, first, num, i;
> +	int cpu, first, i;
>  
> -	/* Pick up a starting point CPU in the mask based on  fuzz */
> -	num = min_t(int, cpumask_weight(mask), nr_cpu_ids);
> -	first = fuzz % num;
> +	/* Pick up a starting point CPU in the mask based on fuzz */
> +	first = fuzz % cpumask_weight(mask);

For this function I've got a deeper rework.

https://lore.kernel.org/all/[email-masked]/

For the rest:
Reviewed-by: Yury Norov <[email-masked]>

>  
>  	/* Locate it */
>  	cpu = cpumask_first(mask);
> -- 
> 2.47.3