[PATCH v2] crypto: caam: Add check for kcalloc() in test_len()

From: Guangshuo Li

Date: Mon Sep 22 2025 - 11:53:46 EST


As kcalloc() may fail, check its return value to avoid a NULL pointer
dereference when passing the buffer to rng->read().

Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
Cc: stable@xxxxxxxxxxxxxxx
---
changelog:
v2:
- Return -ENOMEM directly on allocation failure.

Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/crypto/caam/caamrng.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index b3d14a7f4dd1..357860ee532c 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -182,6 +182,9 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)

buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);

+ if (!buf) {
+ return -ENOMEM;
+ }
while (len > 0) {
read_len = rng->read(rng, buf, len, wait);

--
2.43.0