mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Spelvin <lkml@sdf.org>
To: linux-kernel@vger.kernel.org, lkml@sdf.org
Cc: Thierry Escande <thierry.escande@collabora.com>,
	Samuel Ortiz <sameo@linux.intel.com>,
	linux-nfc@lists.01.org
Subject: [RFC PATCH v1 26/50] drivers/nfc/nfcsim: use prandom_32() for time delay
Date: Wed, 20 Mar 2019 22:50:00 -0400	[thread overview]
Message-ID: <202003281643.02SGhHox023138@sdf.org> (raw)

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@sdf.org>
Cc: Thierry Escande <thierry.escande@collabora.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: linux-nfc@lists.01.org
---
 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


                 reply	other threads:[~2020-03-28 16:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202003281643.02SGhHox023138@sdf.org \
    --to=lkml@sdf.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfc@lists.01.org \
    --cc=sameo@linux.intel.com \
    --cc=thierry.escande@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®