summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2020-03-19 09:12:29 -0700
committerHerbert Xu <herbert@gondor.apana.org.au>2020-03-30 11:50:49 +1100
commit32107e43b505de44ebe1917da2c8c6229acbd509 (patch)
tree07f6546f8cfff4fbef9d02420e694b857fb1aaff
parent2c5e88dc90f50022d1b4bf56c9b45d4162757094 (diff)
downloadlinux-32107e43b505de44ebe1917da2c8c6229acbd509.tar.bz2
crypto: caam - check if RNG job failed
We shouldn't stay silent if RNG job fails. Add appropriate code to check for that case and propagate error code up appropriately. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Cc: Chris Healy <cphealy@gmail.com> Cc: Lucas Stach <l.stach@pengutronix.de> Cc: Horia Geantă <horia.geanta@nxp.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Iuliana Prodan <iuliana.prodan@nxp.com> Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-imx@nxp.com Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/caam/caamrng.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index e64f2d77fa03..d0027d31e840 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -44,6 +44,11 @@ struct caam_rng_ctx {
struct kfifo fifo;
};
+struct caam_rng_job_ctx {
+ struct completion *done;
+ int *err;
+};
+
static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r)
{
return (struct caam_rng_ctx *)r->priv;
@@ -52,12 +57,12 @@ static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r)
static void caam_rng_done(struct device *jrdev, u32 *desc, u32 err,
void *context)
{
- struct completion *done = context;
+ struct caam_rng_job_ctx *jctx = context;
if (err)
- caam_jr_strstatus(jrdev, err);
+ *jctx->err = caam_jr_strstatus(jrdev, err);
- complete(done);
+ complete(jctx->done);
}
static u32 *caam_init_desc(u32 *desc, dma_addr_t dst_dma, int len)
@@ -80,7 +85,11 @@ static int caam_rng_read_one(struct device *jrdev,
struct completion *done)
{
dma_addr_t dst_dma;
- int err;
+ int err, ret = 0;
+ struct caam_rng_job_ctx jctx = {
+ .done = done,
+ .err = &ret,
+ };
len = min_t(int, len, CAAM_RNG_MAX_FIFO_STORE_SIZE);
@@ -93,7 +102,7 @@ static int caam_rng_read_one(struct device *jrdev,
init_completion(done);
err = caam_jr_enqueue(jrdev,
caam_init_desc(desc, dst_dma, len),
- caam_rng_done, done);
+ caam_rng_done, &jctx);
if (err == -EINPROGRESS) {
wait_for_completion(done);
err = 0;
@@ -101,7 +110,7 @@ static int caam_rng_read_one(struct device *jrdev,
dma_unmap_single(jrdev, dst_dma, len, DMA_FROM_DEVICE);
- return err ?: len;
+ return err ?: (ret ?: len);
}
static void caam_rng_fill_async(struct caam_rng_ctx *ctx)