crypto: octeontx2 - prevent underflow in get_cores_bmap()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 17 Dec 2021 07:13:32 +0000 (10:13 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 24 Dec 2021 03:18:27 +0000 (14:18 +1100)
If we're going to cap "eng_grp->g->engs_num" upper bounds then we should
cap the lower bounds as well.

Fixes: 43ac0b824f1c ("crypto: octeontx2 - load microcode and create engine groups")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c

index 27f6d0a0cd3cf172b2334b0992d793e27628c0e8..4c8ebdf671ca8c3a02cc975131583dfac13fdb36 100644 (file)
@@ -29,7 +29,8 @@ static struct otx2_cpt_bitmap get_cores_bmap(struct device *dev,
        bool found = false;
        int i;
 
-       if (eng_grp->g->engs_num > OTX2_CPT_MAX_ENGINES) {
+       if (eng_grp->g->engs_num < 0 ||
+           eng_grp->g->engs_num > OTX2_CPT_MAX_ENGINES) {
                dev_err(dev, "unsupported number of engines %d on octeontx2\n",
                        eng_grp->g->engs_num);
                return bmap;