From 53092a7780fa3d1b926aae8666f1c5a19cb039f1 Mon Sep 17 00:00:00 2001 From: Gatien Chevallier Date: Fri, 26 May 2023 15:49:03 +0200 Subject: [PATCH] fix(st-crypto): do not read RNG data if it's not ready Having RNG_SR_DRDY bit in RNG_SR register does not mean that there are 4 RNG words ready to be read. Add a check on RNG_SR_DRDY between each word reading. Signed-off-by: Gatien Chevallier Change-Id: I46af7ca6c0ddbe19540b248365a5016b15b9a707 --- drivers/st/crypto/stm32_rng.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/st/crypto/stm32_rng.c b/drivers/st/crypto/stm32_rng.c index a9dc43f8d..1342fd454 100644 --- a/drivers/st/crypto/stm32_rng.c +++ b/drivers/st/crypto/stm32_rng.c @@ -187,6 +187,10 @@ int stm32_rng_read(uint8_t *out, uint32_t size) count = 4U; while (len != 0U) { + if ((mmio_read_32(stm32_rng.base + RNG_SR) & RNG_SR_DRDY) == 0U) { + break; + } + data32 = mmio_read_32(stm32_rng.base + RNG_DR); count--;