mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] random: use proper cycle_t type for random_get_entropy()
@ 2022-02-24 17:39 Jason A. Donenfeld
  2022-02-24 21:30 ` [PATCH v2] random: unify cycles_t and jiffies usage and types Jason A. Donenfeld
  0 siblings, 1 reply; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-02-24 17:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jason A. Donenfeld, Theodore Ts'o, Dominik Brodowski

random_get_entropy() returns a cycles_t, not an unsigned long, which is
sometimes 64 bits on various 32-bit platforms, including x86.
Conversely, jiffies is always unsigned long. This commit fixes things to
use cycles_t for fields that use random_get_entropy() and unsigned long
for fields that use jiffies.

Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 19bf44b9ba0f..4e37b8e2acc1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1002,7 +1002,7 @@ int __init rand_initialize(void)
 
 /* There is one of these per entropy source */
 struct timer_rand_state {
-	cycles_t last_time;
+	unsigned long last_time;
 	long last_delta, last_delta2;
 };
 
@@ -1016,7 +1016,7 @@ struct timer_rand_state {
  */
 void add_device_randomness(const void *buf, size_t size)
 {
-	unsigned long time = random_get_entropy() ^ jiffies;
+	cycles_t time = random_get_entropy() ^ jiffies;
 	unsigned long flags;
 
 	if (crng_init == 0 && size)
@@ -1042,8 +1042,8 @@ EXPORT_SYMBOL(add_device_randomness);
 static void add_timer_randomness(struct timer_rand_state *state, unsigned int num)
 {
 	struct {
+		cycles_t cycles;
 		long jiffies;
-		unsigned int cycles;
 		unsigned int num;
 	} sample;
 	long delta, delta2, delta3;
@@ -1356,7 +1356,7 @@ static void entropy_timer(struct timer_list *t)
 static void try_to_generate_entropy(void)
 {
 	struct {
-		unsigned long now;
+		cycles_t now;
 		struct timer_list timer;
 	} stack;
 
-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-25 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 17:39 [PATCH] random: use proper cycle_t type for random_get_entropy() Jason A. Donenfeld
2022-02-24 21:30 ` [PATCH v2] random: unify cycles_t and jiffies usage and types Jason A. Donenfeld
2022-02-25  6:58   ` Dominik Brodowski
2022-02-25 13:39     ` Jason A. Donenfeld
2022-02-25 13:44       ` [PATCH v3] " Jason A. Donenfeld
2022-02-25 14:16         ` Dominik Brodowski

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®