Commit 7cf6e0b6 authored by Guangshuo Li's avatar Guangshuo Li Committed by Herbert Xu
Browse files

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(). On allocation
failure, log the error and return since test_len() returns void.

Fixes: 2be0d806 ("crypto: caam - add a test for the RNG")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGuangshuo Li <lgs201920130244@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 59682835
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -181,7 +181,9 @@ 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);