Skip to content

Commit 77fc95f

Browse files
committed
random: account for arch randomness in bits
Rather than accounting in bytes and multiplying (shifting), we can just account in bits and avoid the shift. The main motivation for this is there are other patches in flux that expand this code a bit, and avoiding the duplication of "* 8" everywhere makes things a bit clearer. Cc: [email protected] Fixes: 12e45a2 ("random: credit architectural init the exact amount") Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 39e0f99 commit 77fc95f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/char/random.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,20 +776,20 @@ static struct notifier_block pm_notifier = { .notifier_call = random_pm_notifica
776776
int __init random_init(const char *command_line)
777777
{
778778
ktime_t now = ktime_get_real();
779-
unsigned int i, arch_bytes;
779+
unsigned int i, arch_bits;
780780
unsigned long entropy;
781781

782782
#if defined(LATENT_ENTROPY_PLUGIN)
783783
static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy;
784784
_mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed));
785785
#endif
786786

787-
for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE;
787+
for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8;
788788
i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) {
789789
if (!arch_get_random_seed_long_early(&entropy) &&
790790
!arch_get_random_long_early(&entropy)) {
791791
entropy = random_get_entropy();
792-
arch_bytes -= sizeof(entropy);
792+
arch_bits -= sizeof(entropy) * 8;
793793
}
794794
_mix_pool_bytes(&entropy, sizeof(entropy));
795795
}
@@ -801,8 +801,8 @@ int __init random_init(const char *command_line)
801801
if (crng_ready())
802802
crng_reseed();
803803
else if (trust_cpu)
804-
_credit_init_bits(arch_bytes * 8);
805-
used_arch_random = arch_bytes * 8 >= POOL_READY_BITS;
804+
_credit_init_bits(arch_bits);
805+
used_arch_random = arch_bits >= POOL_READY_BITS;
806806

807807
WARN_ON(register_pm_notifier(&pm_notifier));
808808

0 commit comments

Comments
 (0)