hwrng: stm32 - fix read of the last word
authorTomas Marek <tomas.marek@elrest.cz>
Wed, 12 Oct 2022 16:09:24 +0000 (18:09 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 21 Oct 2022 11:15:35 +0000 (19:15 +0800)
The stm32_rng_read() function samples TRNG by 4 bytes until at
least 5 bytes are free in the input buffer. The last four bytes
are never read. For example, 60 bytes are returned in case the
input buffer size is 64 bytes.

Read until at least 4 bytes are free in the input buffer. Fill
the buffer entirely in case the buffer size is divisible by 4.

Cc: Oleg Karfich <oleg.karfich@wago.com>
Signed-off-by: Tomas Marek <tomas.marek@elrest.cz>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/stm32-rng.c

index 8eaacefd498bbb4b81b1e6aabf043ff785d67d43..366edda4848b6f9485c3ff1a7f04364a983566b5 100644 (file)
@@ -44,7 +44,7 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 
        pm_runtime_get_sync((struct device *) priv->rng.priv);
 
-       while (max > sizeof(u32)) {
+       while (max >= sizeof(u32)) {
                sr = readl_relaxed(priv->base + RNG_SR);
                /* Manage timeout which is based on timer and take */
                /* care of initial delay time when enabling rng */