diff mbox series

hw_random/timeriomem-rng: Fix cooldown period calculation

Message ID 947aa0ab-1f0c-44d6-943a-cf83a56ac5b8@rwthex-s2-a.rwth-ad.de
State Accepted
Commit e145f5565dc48ccaf4cb50b7cfc48777bed8c100
Headers show
Series hw_random/timeriomem-rng: Fix cooldown period calculation | expand

Commit Message

Jan Henrik Weinstock Feb. 1, 2021, 3:14 p.m. UTC
Ensure cooldown period tolerance of 1% is actually accounted for.

Signed-off-by: Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>
---

Before patch, if period_us was less than 100us, no extra sleep time was 
added. If it was more than 100us, only 1us extra time (and not 1%) is slept.

  drivers/char/hw_random/timeriomem-rng.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

  		retval += sizeof(u32);

Comments

Herbert Xu Feb. 10, 2021, 7:21 a.m. UTC | #1
On Mon, Feb 01, 2021 at 04:14:59PM +0100, Jan Henrik Weinstock wrote:
> Ensure cooldown period tolerance of 1% is actually accounted for.

> 

> Signed-off-by: Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>

> ---

> 

> Before patch, if period_us was less than 100us, no extra sleep time was

> added. If it was more than 100us, only 1us extra time (and not 1%) is slept.

> 

>  drivers/char/hw_random/timeriomem-rng.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)


Patch applied.  Thanks.

BTW your patch was space corrupted so I had to apply it by hand.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
diff mbox series

Patch

diff --git a/drivers/char/hw_random/timeriomem-rng.c 
b/drivers/char/hw_random/timeriomem-rng.c
index e262445fe..f35f0f31f 100644
--- a/drivers/char/hw_random/timeriomem-rng.c
+++ b/drivers/char/hw_random/timeriomem-rng.c
@@ -69,7 +69,7 @@  static int timeriomem_rng_read(struct hwrng *hwrng, 
void *data,
  		 */
  		if (retval > 0)
  			usleep_range(period_us,
-					period_us + min(1, period_us / 100));
+					period_us + max(1, period_us / 100));

  		*(u32 *)data = readl(priv->io_base);