[PATCH] random: fix rdrand mix-in

From: Arnd Bergmann
Date: Tue Jul 17 2018 - 09:53:59 EST


The newly added arch_get_random_int() call was done incorrectly,
using the output only if rdrand hardware was /not/ available. The
compiler points out that the data is uninitialized in this case:

drivers/char/random.c: In function 'write_pool.constprop':
drivers/char/random.c:1912:11: error: 't' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This fixes the condition so we only use that data when it was
valid.

Fixes: 349ddb707fb7 ("random: mix rdrand with entropy sent in from userspace")
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
drivers/char/random.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 283fe390e878..71660aef8c8c 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1907,7 +1907,7 @@ write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
return -EFAULT;

for (b = bytes ; b > 0 ; b -= sizeof(__u32), i++) {
- if (arch_get_random_int(&t))
+ if (!arch_get_random_int(&t))
continue;
buf[i] ^= t;
}
--
2.9.0