Revert "crypto: allwinner - Fix dma_map_sg error check"
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Sep 2022 10:19:27 +0000 (18:19 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Sep 2022 10:19:27 +0000 (18:19 +0800)
This reverts commit 2b02187bdb0bb75000850bd0309e70eb8664159e.

The original code was correct and arguably more robust than the
patched version.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c

index be7f46f..74b4e91 100644 (file)
@@ -208,7 +208,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
 
        if (areq->src == areq->dst) {
                nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_BIDIRECTIONAL);
-               if (!nr_sgs || nr_sgs > MAX_SG) {
+               if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
                        dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
                        err = -EINVAL;
                        goto theend_iv;
@@ -216,13 +216,13 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
                nr_sgd = nr_sgs;
        } else {
                nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE);
-               if (!nr_sgs || nr_sgs > MAX_SG) {
+               if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
                        dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
                        err = -EINVAL;
                        goto theend_iv;
                }
                nr_sgd = dma_map_sg(ce->dev, areq->dst, nd, DMA_FROM_DEVICE);
-               if (!nr_sgd || nr_sgd > MAX_SG) {
+               if (nr_sgd <= 0 || nr_sgd > MAX_SG) {
                        dev_err(ce->dev, "Invalid sg number %d\n", nr_sgd);
                        err = -EINVAL;
                        goto theend_sgs;
index 0e6843e..8b5b9b9 100644 (file)
@@ -389,7 +389,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
        cet->t_asym_ctl = 0;
 
        nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE);
-       if (!nr_sgs || nr_sgs > MAX_SG) {
+       if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
                dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
                err = -EINVAL;
                goto theend;
index fdcc98c..910d675 100644 (file)
@@ -232,13 +232,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
                nr_sgd = nr_sgs;
        } else {
                nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
-               if (!nr_sgs || nr_sgs > 8) {
+               if (nr_sgs <= 0 || nr_sgs > 8) {
                        dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
                        err = -EINVAL;
                        goto theend_iv;
                }
                nr_sgd = dma_map_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
-               if (!nr_sgd || nr_sgd > 8) {
+               if (nr_sgd <= 0 || nr_sgd > 8) {
                        dev_err(ss->dev, "Invalid sg number %d\n", nr_sgd);
                        err = -EINVAL;
                        goto theend_sgs;
index fcb8c41..36a82b2 100644 (file)
@@ -527,7 +527,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
        rctx->method = ss->variant->alg_hash[algt->ss_algo_id];
 
        nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
-       if (!nr_sgs || nr_sgs > MAX_SG) {
+       if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
                dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
                err = -EINVAL;
                goto theend;