[PATCH v8.1 7/7] random: move NUMA-related code to CONFIG_NUMA section

From: Dominik Brodowski
Date: Thu Dec 30 2021 - 03:59:17 EST


By moving crng_initialize_secondary() and crng_init_try_arch() a few
lines lower to the CONFIG_NUMA ifdef section, we can remove the
__maybe_unused attribute from the first function, and reduce the
footprint for !CONFIG_NUMA.

Suggested-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
Signed-off-by: Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>
---
drivers/char/random.c | 52 +++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 26 deletions(-)

v8->v8.1:
crng_init_try_arch() isn't used elsewhere, therefore it needed to be
moved to CONFIG_NUMA as well.

diff --git a/drivers/char/random.c b/drivers/char/random.c
index a5bf662578cb..181b61104948 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -783,24 +783,6 @@ static int __init parse_trust_cpu(char *arg)
}
early_param("random.trust_cpu", parse_trust_cpu);

-static bool crng_init_try_arch(struct crng_state *crng)
-{
- int i;
- bool arch_init = true;
- 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;
- }
- crng->state[i] ^= rv;
- }
-
- return arch_init;
-}
-
static bool __init crng_init_try_arch_early(struct crng_state *crng)
{
int i;
@@ -819,14 +801,6 @@ static bool __init crng_init_try_arch_early(struct crng_state *crng)
return arch_init;
}

-static void __maybe_unused crng_initialize_secondary(struct crng_state *crng)
-{
- chacha_init_consts(crng->state);
- _get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
- crng_init_try_arch(crng);
- crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
-}
-
static void __init crng_initialize_primary(void)
{
struct crng_state *crng = &primary_crng;
@@ -871,6 +845,32 @@ static void crng_finalize_init(struct crng_state *crng)
}

#ifdef CONFIG_NUMA
+static bool crng_init_try_arch(struct crng_state *crng)
+{
+ int i;
+ bool arch_init = true;
+ 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;
+ }
+ crng->state[i] ^= rv;
+ }
+
+ return arch_init;
+}
+
+static void crng_initialize_secondary(struct crng_state *crng)
+{
+ chacha_init_consts(crng->state);
+ _get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
+ crng_init_try_arch(crng);
+ crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
+}
+
static void do_numa_crng_init(struct work_struct *work)
{
int i;