[RFC PATCH v1 26/50] drivers/nfc/nfcsim: use prandom_32() for time delay

From: George Spelvin
Date: Sat Mar 28 2020 - 12:44:16 EST


get_random_bytes() is expensive crypto-quality seed material.
That's not needed for a simple simulation.

(Also, a 3-10 ms delay, when converted to jiffies, isn't a lot of
granularity. It's 1 jiffy at HZ=100 and 3 jiffies at HZ=250
or HZ=300.)

Signed-off-by: George Spelvin <lkml@xxxxxxx>
Cc: Thierry Escande <thierry.escande@xxxxxxxxxxxxx>
Cc: Samuel Ortiz <sameo@xxxxxxxxxxxxxxx>
Cc: linux-nfc@xxxxxxxxxxxx
---
drivers/nfc/nfcsim.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c
index a9864fcdfba6b..eb0a909a25487 100644
--- a/drivers/nfc/nfcsim.c
+++ b/drivers/nfc/nfcsim.c
@@ -229,8 +229,7 @@ static int nfcsim_send(struct nfc_digital_dev *ddev, struct sk_buff *skb,
dev->mode);

/* Add random delay (between 3 and 10 ms) before sending data */
- get_random_bytes(&delay, 1);
- delay = 3 + (delay & 0x07);
+ delay = 3 + prandom_u32_max(8);

schedule_delayed_work(&dev->send_work, msecs_to_jiffies(delay));
}
--
2.26.0