lib/test_printf.c: call wait_for_random_bytes() before plain %p tests
authorThierry Escande <thierry.escande@linaro.org>
Thu, 14 Jun 2018 22:28:15 +0000 (15:28 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 14 Jun 2018 22:55:25 +0000 (07:55 +0900)
If the test_printf module is loaded before the crng is initialized, the
plain 'p' tests will fail because the printed address will not be hashed
and the buffer will contain '(ptrval)' instead.

This patch adds a call to wait_for_random_bytes() before plain 'p' tests
to make sure the crng is initialized.

Link: http://lkml.kernel.org/r/20180604113708.11554-1-thierry.escande@linaro.org
Signed-off-by: Thierry Escande <thierry.escande@linaro.org>
Acked-by: Tobin C. Harding <me@tobin.cc>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: David Miller <davem@davemloft.net>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/test_printf.c

index cea592f402ed029d6d5dd63addd2d2bc8a8391f1..b2aa8f5148449de1557e3ee48feebb8f1cab3083 100644 (file)
@@ -260,6 +260,13 @@ plain(void)
 {
        int err;
 
 {
        int err;
 
+       /*
+        * Make sure crng is ready. Otherwise we get "(ptrval)" instead
+        * of a hashed address when printing '%p' in plain_hash() and
+        * plain_format().
+        */
+       wait_for_random_bytes();
+
        err = plain_hash();
        if (err) {
                pr_warn("plain 'p' does not appear to be hashed\n");
        err = plain_hash();
        if (err) {
                pr_warn("plain 'p' does not appear to be hashed\n");