crypto: iaa - Fix nr_cpus < nr_iaa case

If nr_cpus < nr_iaa, the calculated cpus_per_iaa will be 0, which
causes a divide-by-0 in rebalance_wq_table().

Make sure cpus_per_iaa is 1 in that case, and also in the nr_iaa == 0
case, even though cpus_per_iaa is never used if nr_iaa == 0, for
paranoia.

Cc: <stable@vger.kernel.org> # v6.8+
Reported-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Tom Zanussi 2024-03-21 16:08:45 -05:00 committed by Herbert Xu
parent 203a6763ab
commit 5a7e89d331
1 changed files with 7 additions and 3 deletions

View File

@ -806,6 +806,8 @@ static int save_iaa_wq(struct idxd_wq *wq)
return -EINVAL; return -EINVAL;
cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa; cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa;
if (!cpus_per_iaa)
cpus_per_iaa = 1;
out: out:
return 0; return 0;
} }
@ -821,10 +823,12 @@ static void remove_iaa_wq(struct idxd_wq *wq)
} }
} }
if (nr_iaa) if (nr_iaa) {
cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa; cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa;
else if (!cpus_per_iaa)
cpus_per_iaa = 0; cpus_per_iaa = 1;
} else
cpus_per_iaa = 1;
} }
static int wq_table_add_wqs(int iaa, int cpu) static int wq_table_add_wqs(int iaa, int cpu)