]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: iaa - Fix nr_cpus < nr_iaa case
authorTom Zanussi <tom.zanussi@linux.intel.com>
Thu, 21 Mar 2024 21:08:45 +0000 (16:08 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Apr 2024 13:32:36 +0000 (15:32 +0200)
commit 5a7e89d3315d1be86aff8a8bf849023cda6547f7 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/crypto/intel/iaa/iaa_crypto_main.c

index dfd3baf0a8d873747b3103785f2fde6236cf96bb..aa65c1791ce7671c7d69bdeefdd648adae7d9263 100644 (file)
@@ -908,6 +908,8 @@ static int save_iaa_wq(struct idxd_wq *wq)
                return -EINVAL;
 
        cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa;
+       if (!cpus_per_iaa)
+               cpus_per_iaa = 1;
 out:
        return 0;
 }
@@ -923,10 +925,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;
-       else
-               cpus_per_iaa = 0;
+               if (!cpus_per_iaa)
+                       cpus_per_iaa = 1;
+       } else
+               cpus_per_iaa = 1;
 }
 
 static int wq_table_add_wqs(int iaa, int cpu)