Re: [PATCH] padata: Fix possible divide-by-0 panic in padata_mt_helper()
From: Herbert Xu
Date: Sat Aug 10 2024 - 00:05:40 EST
Waiman Long <longman@xxxxxxxxxx> wrote:
>
> diff --git a/kernel/padata.c b/kernel/padata.c
> index 53f4bc912712..0fa6c2895460 100644
> --- a/kernel/padata.c
> +++ b/kernel/padata.c
> @@ -517,6 +517,13 @@ void __init padata_do_multithreaded(struct padata_mt_job *job)
> ps.chunk_size = max(ps.chunk_size, job->min_chunk);
> ps.chunk_size = roundup(ps.chunk_size, job->align);
>
> + /*
> + * chunk_size can be 0 if the caller sets min_chunk to 0. So force it
> + * to at least 1 to prevent divide-by-0 panic in padata_mt_helper().`
> + */
> + if (!ps.chunk_size)
> + ps.chunk_size = 1U;
Perhaps change the first ps.chunk_size assignment to use DIV_ROUND_UP
instead?
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt