From 3c6db0958d6f6c56e998dca8de06336ca8e176cf Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 24 May 2023 16:00:07 +0200 Subject: [PATCH] drivers: stm32_rng: fix case when RNG is not ready Checks RNG data ready status bit before each read of a 32bit sample from the RNG FIFO. Indeed the data ready status bit tells that the RNG FIFO contains random bytes by burst of 32bit word, not by burst of 4 32bit words. Change-Id: Id12162d9c405b9574559568fa90f48f9afa7d1bb Signed-off-by: Etienne Carriere --- core/drivers/stm32_rng.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/drivers/stm32_rng.c b/core/drivers/stm32_rng.c index ef5862308..b3f2e3f81 100644 --- a/core/drivers/stm32_rng.c +++ b/core/drivers/stm32_rng.c @@ -140,9 +140,13 @@ static TEE_Result stm32_rng_read_available(struct stm32_rng_device *dev, /* RNG is ready: read up to 4 32bit words */ while (size) { - uint32_t data32 = io_read32(base + RNG_DR); + uint32_t data32 = 0; size_t sz = MIN(size, sizeof(uint32_t)); + if (!(io_read32(base + RNG_SR) & RNG_SR_DRDY)) + return TEE_ERROR_NO_DATA; + + data32 = io_read32(base + RNG_DR); memcpy(buf, &data32, sz); buf += sz; size -= sz; -- 2.17.1