mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
random: Avoid open-coded use of ratelimit_state structure's ->missed field
The _credit_init_bits() function directly accesses the ratelimit_state structure's ->missed field, which works, but which also makes it more difficult to change this field. Therefore, make use of the ratelimit_state_get_miss() and ratelimit_state_inc_miss() functions instead of directly accessing the ->missed field. Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/20250423115409.3425-1-spasswolf@web.de/ Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Cc: "Theodore Ts'o" <tytso@mit.edu> "Jason A. Donenfeld" <Jason@zx2c4.com>
This commit is contained in:
@@ -726,6 +726,7 @@ static void __cold _credit_init_bits(size_t bits)
|
||||
static DECLARE_WORK(set_ready, crng_set_ready);
|
||||
unsigned int new, orig, add;
|
||||
unsigned long flags;
|
||||
int m;
|
||||
|
||||
if (!bits)
|
||||
return;
|
||||
@@ -748,9 +749,9 @@ static void __cold _credit_init_bits(size_t bits)
|
||||
wake_up_interruptible(&crng_init_wait);
|
||||
kill_fasync(&fasync, SIGIO, POLL_IN);
|
||||
pr_notice("crng init done\n");
|
||||
if (urandom_warning.missed)
|
||||
pr_notice("%d urandom warning(s) missed due to ratelimiting\n",
|
||||
urandom_warning.missed);
|
||||
m = ratelimit_state_get_miss(&urandom_warning);
|
||||
if (m)
|
||||
pr_notice("%d urandom warning(s) missed due to ratelimiting\n", m);
|
||||
} else if (orig < POOL_EARLY_BITS && new >= POOL_EARLY_BITS) {
|
||||
spin_lock_irqsave(&base_crng.lock, flags);
|
||||
/* Check if crng_init is CRNG_EMPTY, to avoid race with crng_reseed(). */
|
||||
@@ -1466,7 +1467,7 @@ static ssize_t urandom_read_iter(struct kiocb *kiocb, struct iov_iter *iter)
|
||||
|
||||
if (!crng_ready()) {
|
||||
if (!ratelimit_disable && maxwarn <= 0)
|
||||
++urandom_warning.missed;
|
||||
ratelimit_state_inc_miss(&urandom_warning);
|
||||
else if (ratelimit_disable || __ratelimit(&urandom_warning)) {
|
||||
--maxwarn;
|
||||
pr_notice("%s: uninitialized urandom read (%zu bytes read)\n",
|
||||
|
||||
Reference in New Issue
Block a user