Re: [PATCH] workqueue: Fix divide error in wq_update_node_max_active()

From: Tejun Heo
Date: Tue Apr 23 2024 - 12:11:13 EST


Hello, Lai.

On Tue, Apr 23, 2024 at 08:45:48PM +0800, Lai Jiangshan wrote:
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 0066c8f6c154..b31cd7faeb9f 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -1591,7 +1591,7 @@ static void wq_update_node_max_active(struct workqueue_struct *wq, int off_cpu)
> off_cpu = -1;
>
> total_cpus = cpumask_weight_and(effective, cpu_online_mask);
> - if (off_cpu >= 0)
> + if (off_cpu >= 0 && total_cpus > 1)
> total_cpus--;

Can we do this explicitly instead? ie. test total_cpus before using it as
divisor and use max_active explicitly if it's zero.

Thanks.

--
tejun