Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: stable@vger.kernel.org
Fixes: 12e45a2a6308 ("random: credit architectural init the exact amount")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

+5 -5
+5 -5
drivers/char/random.c
··· 776 776 int __init random_init(const char *command_line) 777 777 { 778 778 ktime_t now = ktime_get_real(); 779 - unsigned int i, arch_bytes; 779 + unsigned int i, arch_bits; 780 780 unsigned long entropy; 781 781 782 782 #if defined(LATENT_ENTROPY_PLUGIN) ··· 784 784 _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); 785 785 #endif 786 786 787 - for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE; 787 + for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8; 788 788 i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) { 789 789 if (!arch_get_random_seed_long_early(&entropy) && 790 790 !arch_get_random_long_early(&entropy)) { 791 791 entropy = random_get_entropy(); 792 - arch_bytes -= sizeof(entropy); 792 + arch_bits -= sizeof(entropy) * 8; 793 793 } 794 794 _mix_pool_bytes(&entropy, sizeof(entropy)); 795 795 } ··· 801 801 if (crng_ready()) 802 802 crng_reseed(); 803 803 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; 806 806 807 807 WARN_ON(register_pm_notifier(&pm_notifier)); 808 808