Skip to content

Commit

Permalink
lib/test_printf.c: accept "ptrval" as valid result for plain 'p' tests
Browse files Browse the repository at this point in the history
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____)" or "(ptrval)" instead
(64-bit vs 32-bit).
Since we cannot wait for the crng to be initialized for an undefined
time, both plain 'p' tests now accept the strings "(____ptrval____)" or
"(ptrval)" as a valid result and print a warning message.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: ad67b74 ("printk: hash addresses printed with %p")
To: Andrew Morton <[email protected]>
To: David Miller <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: "Tobin C . Harding" <[email protected]>
Cc: [email protected]
Signed-off-by: Thierry Escande <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
  • Loading branch information
Thierry Escande authored and pmladek committed Jun 15, 2018
1 parent d75ae5b commit ce041c4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/test_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ test_string(void)
#define PTR_WIDTH 16
#define PTR ((void *)0xffff0123456789abUL)
#define PTR_STR "ffff0123456789ab"
#define PTR_VAL_NO_CRNG "(____ptrval____)"
#define ZEROS "00000000" /* hex 32 zero bits */

static int __init
Expand All @@ -216,7 +217,16 @@ plain_format(void)

nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR);

if (nchars != PTR_WIDTH || strncmp(buf, ZEROS, strlen(ZEROS)) != 0)
if (nchars != PTR_WIDTH)
return -1;

if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) {
pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"",
PTR_VAL_NO_CRNG);
return 0;
}

if (strncmp(buf, ZEROS, strlen(ZEROS)) != 0)
return -1;

return 0;
Expand All @@ -227,6 +237,7 @@ plain_format(void)
#define PTR_WIDTH 8
#define PTR ((void *)0x456789ab)
#define PTR_STR "456789ab"
#define PTR_VAL_NO_CRNG "(ptrval)"

static int __init
plain_format(void)
Expand All @@ -245,7 +256,16 @@ plain_hash(void)

nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR);

if (nchars != PTR_WIDTH || strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
if (nchars != PTR_WIDTH)
return -1;

if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) {
pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"",
PTR_VAL_NO_CRNG);
return 0;
}

if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
return -1;

return 0;
Expand Down

0 comments on commit ce041c4

Please sign in to comment.