]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
random: unify cycles_t and jiffies usage and types
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 24 Feb 2022 17:30:58 +0000 (18:30 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Jun 2022 09:46:36 +0000 (11:46 +0200)
commitddb672cf1d04dea810e82c59ce6773920ed0333e
treee0c400293f23ed58cc399e81edef8ab208e9e78a
parent55add4d8bc3227bab90dff66301510623268e3bd
random: unify cycles_t and jiffies usage and types

commit abded93ec1e9692920fe309f07f40bd1035f2940 upstream.

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(), named "cycles",
and unsigned long for fields that use jiffies, named "now". It's also
good to mix in a cycles_t and a jiffies in the same way for both
add_device_randomness and add_timer_randomness, rather than using xor in
one case. Finally, we unify the order of these volatile reads, always
reading the more precise cycles counter, and then jiffies, so that the
cycle counter is as close to the event as possible.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c