[PATCH] random: yell if random_get_entropy() returns a constant
From: Sebastian Andrzej Siewior
Date: Fri Apr 04 2014 - 12:49:29 EST
A few architectures still return 0 (i.e. a constant) if
random_get_entropy() is invoked. Make them aware of this so they may fix
this.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
drivers/char/random.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 429b75b..48775f8 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -241,6 +241,7 @@
#include <linux/major.h>
#include <linux/string.h>
#include <linux/fcntl.h>
+#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/poll.h>
@@ -1675,3 +1676,23 @@ randomize_range(unsigned long start, unsigned long end, unsigned long len)
return 0;
return PAGE_ALIGN(get_random_int() % range + start);
}
+
+static int check_random_get_entropy(void)
+{
+ cycles_t cyc1;
+ cycles_t cyc2;
+
+ cyc1 = random_get_entropy();
+ cyc2 = random_get_entropy();
+ if (cyc1 != cyc2)
+ return 0;
+ udelay(1);
+ cyc2 = random_get_entropy();
+
+ if (cyc1 != cyc2)
+ return 0;
+ pr_err("Error: random_get_entropy() does not return anything random\n");
+ WARN_ON(1);
+ return -EINVAL;
+}
+late_initcall(check_random_get_entropy);
--
1.9.1
> Cheers,
> - Ted
Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/