Skip to contentSkip to conversation

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

PATCH In review Guangshuo Li 2 participants 2 messages Sep 18, 2025

Subsystems (3)
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 | 1 -
 1 file changed, 1 deletion(-)
drivers/crypto/caam/caamrng.c +0 -1
index e0adb326f496..d887ecf6f99d 100644
@@ -183,7 +183,6 @@ 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) {
-		dev_err(dev, "RNG buffer allocation failed\n");
 		return;
 	}
 	while (len > 0) {
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines · Guangshuo Li

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().

But that is not what this patch does :(

Quoted 2 lines
Fixes 2be0d806e25e ("crypto: caam - add a test for the RNG")

No need for stable here.

Quoted 10 lines
---
 drivers/crypto/caam/caamrng.c | 1 -
 1 file changed, 1 deletion(-)
drivers/crypto/caam/caamrng.c +0 -0
index e0adb326f496..d887ecf6f99d 100644

drivers/crypto/caam/caamrng.c static inline void test_len(struct hwrng *rng, size_t len, bool wait) · line 187

Quoted 6 lines
drivers/crypto/caam/caamrng.c +0 -1
@@ -183,7 +183,6 @@ 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) {
-		dev_err(dev, "RNG buffer allocation failed\n");
 		return;
 	}

checkpatch should show that you can remove the { } now, right?

thanks,

greg k-h