[PATCH] crypto: fix potential null pointer dereference on pointer dd

From: Chengfeng Ye
Date: Sat Oct 30 2021 - 09:36:20 EST


The return pointer of atmel_sha_find_dev could
be null, there could be potential null-deref issue.
Fix this by adding a null check.

Signed-off-by: Chengfeng Ye <cyeaa@xxxxxxxxxxxxxx>
---
drivers/crypto/atmel-sha.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 1b13f601fd95..f6ea5aadb86a 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -430,6 +430,9 @@ static int atmel_sha_init(struct ahash_request *req)
struct atmel_sha_reqctx *ctx = ahash_request_ctx(req);
struct atmel_sha_dev *dd = atmel_sha_find_dev(tctx);

+ if (!dd)
+ return -EINVAL;
+
ctx->dd = dd;

ctx->flags = 0;
--
2.17.1