[PATCH] random: Clean up NUMA allocations

From: Michael Ellerman
Date: Sat Jul 30 2016 - 22:54:40 EST


Use kcalloc(), rather than doing the multiply by hand. Use sizeof(*pool)
rather than assuming it's == sizeof(void *). kcalloc() zeroes by default
so we don't need __GFP_ZERO.

Drop the __GFP_NOFAILs, we can easily handle allocation failures, the
code is already written to cope with a NULL crng_node_pool, or a NULL
entry for a given node in the pool.

Signed-off-by: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
---
drivers/char/random.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index ea03dfe2f21c..22c8ac173666 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1666,11 +1666,15 @@ static int rand_initialize(void)
crng_initialize(&primary_crng);

#ifdef CONFIG_NUMA
- pool = kmalloc(nr_node_ids * sizeof(void *),
- GFP_KERNEL|__GFP_NOFAIL|__GFP_ZERO);
+ pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL);
+ if (!pool)
+ return 0;
+
for_each_online_node(i) {
- crng = kmalloc_node(sizeof(struct crng_state),
- GFP_KERNEL | __GFP_NOFAIL, i);
+ crng = kmalloc_node(sizeof(struct crng_state), GFP_KERNEL, i);
+ if (!crng)
+ continue;
+
spin_lock_init(&crng->lock);
crng_initialize(crng);
pool[i] = crng;
--
2.7.4