]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
crypto: qat - Clean up error handling in qat_dh_set_secret()
authorEric Biggers <ebiggers@google.com>
Mon, 6 Nov 2017 02:30:47 +0000 (18:30 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 10 Nov 2017 11:20:20 +0000 (19:20 +0800)
Update the error handling in qat_dh_set_secret() to mirror
dh_set_secret().  The new version is less error-prone because freeing
memory and setting the pointers to NULL is now only done in one place.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/qat/qat_common/qat_asym_algs.c

index 6f5dd68449c65fb3cb91b8eceecfe96439d2a883..7655fdb499de5a948453eff1f15888ae81d0a116 100644 (file)
@@ -462,11 +462,8 @@ static int qat_dh_set_params(struct qat_dh_ctx *ctx, struct dh *params)
        }
 
        ctx->g = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_g, GFP_KERNEL);
-       if (!ctx->g) {
-               dma_free_coherent(dev, ctx->p_size, ctx->p, ctx->dma_p);
-               ctx->p = NULL;
+       if (!ctx->g)
                return -ENOMEM;
-       }
        memcpy(ctx->g + (ctx->p_size - params->g_size), params->g,
               params->g_size);
 
@@ -507,18 +504,22 @@ static int qat_dh_set_secret(struct crypto_kpp *tfm, const void *buf,
 
        ret = qat_dh_set_params(ctx, &params);
        if (ret < 0)
-               return ret;
+               goto err_clear_ctx;
 
        ctx->xa = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_xa,
                                      GFP_KERNEL);
        if (!ctx->xa) {
-               qat_dh_clear_ctx(dev, ctx);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err_clear_ctx;
        }
        memcpy(ctx->xa + (ctx->p_size - params.key_size), params.key,
               params.key_size);
 
        return 0;
+
+err_clear_ctx:
+       qat_dh_clear_ctx(dev, ctx);
+       return ret;
 }
 
 static unsigned int qat_dh_max_size(struct crypto_kpp *tfm)