Skip to contentSkip to conversation

crypto: caam: Add check for kcalloc() in test_len()

PATCH Superseded Guangshuo Li 1 participant 1 message Sep 18, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: caam: Add check for kcalloc() in test_len()

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

Fixes 2be0d806e25e ("crypto: caam - add a test for the RNG")
---
 drivers/crypto/caam/caamrng.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam/caamrng.c +2 -1
index b3d14a7f4dd1..003c5e37acbe 100644
@@ -181,7 +181,8 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)
 	struct device *dev = ctx->ctrldev;
 
 	buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);
-
+	if (!buf)
+		return;
 	while (len > 0) {
 		read_len = rng->read(rng, buf, len, wait);
 
Signature · 1 line
2.43.0