Skip to content

Commit 48e864a

Browse files
committed
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/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: "Theodore Ts'o" <[email protected]> "Jason A. Donenfeld" <[email protected]>
1 parent 56a7b9f commit 48e864a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/char/random.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ static void __cold _credit_init_bits(size_t bits)
726726
static DECLARE_WORK(set_ready, crng_set_ready);
727727
unsigned int new, orig, add;
728728
unsigned long flags;
729+
int m;
729730

730731
if (!bits)
731732
return;
@@ -748,9 +749,9 @@ static void __cold _credit_init_bits(size_t bits)
748749
wake_up_interruptible(&crng_init_wait);
749750
kill_fasync(&fasync, SIGIO, POLL_IN);
750751
pr_notice("crng init done\n");
751-
if (urandom_warning.missed)
752-
pr_notice("%d urandom warning(s) missed due to ratelimiting\n",
753-
urandom_warning.missed);
752+
m = ratelimit_state_get_miss(&urandom_warning);
753+
if (m)
754+
pr_notice("%d urandom warning(s) missed due to ratelimiting\n", m);
754755
} else if (orig < POOL_EARLY_BITS && new >= POOL_EARLY_BITS) {
755756
spin_lock_irqsave(&base_crng.lock, flags);
756757
/* 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)
14661467

14671468
if (!crng_ready()) {
14681469
if (!ratelimit_disable && maxwarn <= 0)
1469-
++urandom_warning.missed;
1470+
ratelimit_state_inc_miss(&urandom_warning);
14701471
else if (ratelimit_disable || __ratelimit(&urandom_warning)) {
14711472
--maxwarn;
14721473
pr_notice("%s: uninitialized urandom read (%zu bytes read)\n",

0 commit comments

Comments
 (0)