Skip to content

Commit 32107e4

Browse files
ndreysherbertx
authored andcommitted
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 <[email protected]> Reviewed-by: Horia Geantă <[email protected]> Cc: Chris Healy <[email protected]> Cc: Lucas Stach <[email protected]> Cc: Horia Geantă <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Iuliana Prodan <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent 2c5e88d commit 32107e4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/crypto/caam/caamrng.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ struct caam_rng_ctx {
4444
struct kfifo fifo;
4545
};
4646

47+
struct caam_rng_job_ctx {
48+
struct completion *done;
49+
int *err;
50+
};
51+
4752
static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r)
4853
{
4954
return (struct caam_rng_ctx *)r->priv;
@@ -52,12 +57,12 @@ static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r)
5257
static void caam_rng_done(struct device *jrdev, u32 *desc, u32 err,
5358
void *context)
5459
{
55-
struct completion *done = context;
60+
struct caam_rng_job_ctx *jctx = context;
5661

5762
if (err)
58-
caam_jr_strstatus(jrdev, err);
63+
*jctx->err = caam_jr_strstatus(jrdev, err);
5964

60-
complete(done);
65+
complete(jctx->done);
6166
}
6267

6368
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,
8085
struct completion *done)
8186
{
8287
dma_addr_t dst_dma;
83-
int err;
88+
int err, ret = 0;
89+
struct caam_rng_job_ctx jctx = {
90+
.done = done,
91+
.err = &ret,
92+
};
8493

8594
len = min_t(int, len, CAAM_RNG_MAX_FIFO_STORE_SIZE);
8695

@@ -93,15 +102,15 @@ static int caam_rng_read_one(struct device *jrdev,
93102
init_completion(done);
94103
err = caam_jr_enqueue(jrdev,
95104
caam_init_desc(desc, dst_dma, len),
96-
caam_rng_done, done);
105+
caam_rng_done, &jctx);
97106
if (err == -EINPROGRESS) {
98107
wait_for_completion(done);
99108
err = 0;
100109
}
101110

102111
dma_unmap_single(jrdev, dst_dma, len, DMA_FROM_DEVICE);
103112

104-
return err ?: len;
113+
return err ?: (ret ?: len);
105114
}
106115

107116
static void caam_rng_fill_async(struct caam_rng_ctx *ctx)

0 commit comments

Comments
 (0)