Skip to content

Commit 7b87324

Browse files
committed
random: use IS_ENABLED(CONFIG_NUMA) instead of ifdefs
Rather than an awkward combination of ifdefs and __maybe_unused, we can ensure more source gets parsed, regardless of the configuration, by using IS_ENABLED for the CONFIG_NUMA conditional code. This makes things cleaner and easier to follow. I've confirmed that on !CONFIG_NUMA, we don't wind up with excess code by accident; the generated object file is the same. Reviewed-by: Dominik Brodowski <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 161212c commit 7b87324

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

drivers/char/random.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,13 @@ static int credit_entropy_bits_safe(struct entropy_store *r, int nbits)
759759

760760
static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait);
761761

762-
#ifdef CONFIG_NUMA
763762
/*
764763
* Hack to deal with crazy userspace progams when they are all trying
765764
* to access /dev/urandom in parallel. The programs are almost
766765
* certainly doing something terribly wrong, but we'll work around
767766
* their brain damage.
768767
*/
769768
static struct crng_state **crng_node_pool __read_mostly;
770-
#endif
771769

772770
static void invalidate_batched_entropy(void);
773771
static void numa_crng_init(void);
@@ -815,7 +813,7 @@ static bool __init crng_init_try_arch_early(struct crng_state *crng)
815813
return arch_init;
816814
}
817815

818-
static void __maybe_unused crng_initialize_secondary(struct crng_state *crng)
816+
static void crng_initialize_secondary(struct crng_state *crng)
819817
{
820818
chacha_init_consts(crng->state);
821819
_get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
@@ -866,7 +864,6 @@ static void crng_finalize_init(struct crng_state *crng)
866864
}
867865
}
868866

869-
#ifdef CONFIG_NUMA
870867
static void do_numa_crng_init(struct work_struct *work)
871868
{
872869
int i;
@@ -893,29 +890,24 @@ static DECLARE_WORK(numa_crng_init_work, do_numa_crng_init);
893890

894891
static void numa_crng_init(void)
895892
{
896-
schedule_work(&numa_crng_init_work);
893+
if (IS_ENABLED(CONFIG_NUMA))
894+
schedule_work(&numa_crng_init_work);
897895
}
898896

899897
static struct crng_state *select_crng(void)
900898
{
901-
struct crng_state **pool;
902-
int nid = numa_node_id();
903-
904-
/* pairs with cmpxchg_release() in do_numa_crng_init() */
905-
pool = READ_ONCE(crng_node_pool);
906-
if (pool && pool[nid])
907-
return pool[nid];
899+
if (IS_ENABLED(CONFIG_NUMA)) {
900+
struct crng_state **pool;
901+
int nid = numa_node_id();
908902

909-
return &primary_crng;
910-
}
911-
#else
912-
static void numa_crng_init(void) {}
903+
/* pairs with cmpxchg_release() in do_numa_crng_init() */
904+
pool = READ_ONCE(crng_node_pool);
905+
if (pool && pool[nid])
906+
return pool[nid];
907+
}
913908

914-
static struct crng_state *select_crng(void)
915-
{
916909
return &primary_crng;
917910
}
918-
#endif
919911

920912
/*
921913
* crng_fast_load() can be called by code in the interrupt service

0 commit comments

Comments
 (0)