Skip to content

Commit 5a7e89d

Browse files
tzanussiherbertx
authored andcommitted
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>
1 parent 203a676 commit 5a7e89d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/crypto/intel/iaa/iaa_crypto_main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ static int save_iaa_wq(struct idxd_wq *wq)
806806
return -EINVAL;
807807

808808
cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa;
809+
if (!cpus_per_iaa)
810+
cpus_per_iaa = 1;
809811
out:
810812
return 0;
811813
}
@@ -821,10 +823,12 @@ static void remove_iaa_wq(struct idxd_wq *wq)
821823
}
822824
}
823825

824-
if (nr_iaa)
826+
if (nr_iaa) {
825827
cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa;
826-
else
827-
cpus_per_iaa = 0;
828+
if (!cpus_per_iaa)
829+
cpus_per_iaa = 1;
830+
} else
831+
cpus_per_iaa = 1;
828832
}
829833

830834
static int wq_table_add_wqs(int iaa, int cpu)

0 commit comments

Comments
 (0)