diff mbox series

[4/4] random: Apply get_source_long() in several places

Message ID CACXcFmm7Bxnctksf2e96+f7UZk_HjHSJwiCakPuBfdGX5d=T9A@mail.gmail.com (mailing list archive)
State Not Applicable
Delegated to: Herbert Xu
Headers show
Series random: change usage of arch_get_random_long() | expand

Commit Message

Sandy Harris Feb. 10, 2022, 2:44 p.m. UTC
Replace arch_get_random_long()/random_get_entropy() sequences
with get_source_long().

Signed-off-by: Sandy Harris <sandyinchina@gmail.com>
---
 drivers/char/random.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

     memzero_explicit(&buf, sizeof(buf));
@@ -1728,6 +1717,7 @@ static void extract_buf(u8 *out)
     u8 hash[BLAKE2S_HASH_SIZE];
     unsigned long *salt;
     unsigned long flags;
+    unsigned long v ;

     blake2s_init(&state, sizeof(hash));

@@ -1737,10 +1727,8 @@ static void extract_buf(u8 *out)
      */
     for (salt = (unsigned long *)&state.h[4];
          salt < (unsigned long *)&state.h[8]; ++salt) {
-        unsigned long v;
-        if (!arch_get_random_long(&v))
-            break;
-        *salt ^= v;
+        get_source_long(&v) ;
+        *salt ^= v ;
     }

     /* Generate a hash across the pool */
@@ -2037,9 +2025,7 @@ int __must_check get_random_bytes_arch(void
*buf, int nbytes)
         unsigned long v;
         int chunk = min_t(int, left, sizeof(unsigned long));

-        if (!arch_get_random_long(&v))
-            break;
-
+        get_source_long(&v) ;
         memcpy(p, &v, chunk);
         p += chunk;
         left -= chunk;
@@ -2064,9 +2050,7 @@ static void __init init_std_data(void)

     mix_pool_bytes(&now, sizeof(now));
     for (i = POOL_BYTES; i > 0; i -= sizeof(rv)) {
-        if (!arch_get_random_seed_long(&rv) &&
-            !arch_get_random_long(&rv))
-            rv = random_get_entropy();
+        get_source_long(&rv) ;
         mix_pool_bytes(&rv, sizeof(rv));
     }
     mix_pool_bytes(utsname(), sizeof(*(utsname())));

Comments

Greg Kroah-Hartman Feb. 10, 2022, 3:20 p.m. UTC | #1
On Thu, Feb 10, 2022 at 10:44:44PM +0800, Sandy Harris wrote:
> Replace arch_get_random_long()/random_get_entropy() sequences
> with get_source_long().

This says what you want to do, but nothing about _why_ you want to do
it.

Please read the documentation for how to write good changelog texts.
As-is, this doesn't work.

Also, the patch is whitespace corrupted :(

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 6c77fd056f66..20af61a56ec0 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1140,11 +1140,7 @@  static bool crng_init_try_arch(struct crng_state *crng)
     unsigned long rv;

     for (i = 4; i < 16; i++) {
-        if (!arch_get_random_seed_long(&rv) &&
-            !arch_get_random_long(&rv)) {
-            rv = random_get_entropy();
-            arch_init = false;
-        }
+        get_source_long(&rv) ;
         crng->state[i] ^= rv;
     }

@@ -1158,11 +1154,7 @@  static bool __init crng_init_try_arch_early(void)
     unsigned long rv;

     for (i = 4; i < 16; i++) {
-        if (!arch_get_random_seed_long_early(&rv) &&
-            !arch_get_random_long_early(&rv)) {
-            rv = random_get_entropy();
-            arch_init = false;
-        }
+        get_source_long(&rv) ;
         primary_crng.state[i] ^= rv;
     }

@@ -1341,7 +1333,7 @@  static int crng_slow_load(const u8 *cp, size_t len)

 static void crng_reseed(struct crng_state *crng, bool use_input_pool)
 {
-    unsigned long flags;
+    unsigned long flags, rv;
     int i, num;
     union {
         u8 block[CHACHA_BLOCK_SIZE];
@@ -1359,10 +1351,7 @@  static void crng_reseed(struct crng_state
*crng, bool use_input_pool)
     }
     spin_lock_irqsave(&crng->lock, flags);
     for (i = 0; i < 8; i++) {
-        unsigned long rv;
-        if (!arch_get_random_seed_long(&rv) &&
-            !arch_get_random_long(&rv))
-            rv = random_get_entropy();
+        get_source_long(&rv) ;
         crng->state[i + 4] ^= buf.key[i] ^ rv;
     }