printk: fix printing 64-bit hex values

These were being truncated to 32-bits, and only 8
hex digits were supported.

An extraneous printk() at the beginning of the test
which was not being tested in any way has been removed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-01-11 14:45:15 -08:00 committed by Kumar Gala
parent f2c03280f2
commit dfeed647f5
2 changed files with 13 additions and 15 deletions

View file

@ -33,7 +33,7 @@ static void _printk_dec_ulong(out_func_t out, void *ctx,
const unsigned long num, enum pad_type padding, const unsigned long num, enum pad_type padding,
int min_width); int min_width);
static void _printk_hex_ulong(out_func_t out, void *ctx, static void _printk_hex_ulong(out_func_t out, void *ctx,
const unsigned long num, enum pad_type padding, const unsigned long long num, enum pad_type padding,
int min_width); int min_width);
/** /**
@ -179,13 +179,12 @@ void _vprintk(out_func_t out, void *ctx, const char *fmt, va_list ap)
/* Fall through */ /* Fall through */
case 'x': case 'x':
case 'X': { case 'X': {
unsigned long x; unsigned long long x;
if (long_ctr < 2) { if (long_ctr < 2) {
x = va_arg(ap, unsigned long); x = va_arg(ap, unsigned long);
} else { } else {
x = (unsigned long)va_arg(ap, x = va_arg(ap, unsigned long long);
unsigned long long);
} }
_printk_hex_ulong(out, ctx, x, padding, _printk_hex_ulong(out, ctx, x, padding,
@ -346,21 +345,22 @@ void printk(const char *fmt, ...)
} }
/** /**
* @brief Output an unsigned long in hex format * @brief Output an unsigned long long in hex format
* *
* Output an unsigned long on output installed by platform at init time. Should * Output an unsigned long long on output installed by platform at init time.
* be able to handle an unsigned long of any size, 32 or 64 bit. * Able to print full 64-bit values.
* @param num Number to output * @param num Number to output
* *
* @return N/A * @return N/A
*/ */
static void _printk_hex_ulong(out_func_t out, void *ctx, static void _printk_hex_ulong(out_func_t out, void *ctx,
const unsigned long num, enum pad_type padding, const unsigned long long num,
enum pad_type padding,
int min_width) int min_width)
{ {
int size = sizeof(num) * 2; int size = sizeof(num) * 2;
int found_largest_digit = 0; int found_largest_digit = 0;
int remaining = 8; /* 8 digits max */ int remaining = 16; /* 16 digits max */
int digits = 0; int digits = 0;
for (; size; size--) { for (; size; size--) {

View file

@ -18,14 +18,14 @@ int (*_old_char_out)(int);
char *expected = "22 113 10000 32768 40000 22\n" char *expected = "22 113 10000 32768 40000 22\n"
"p 112 -10000 -32768 -40000 -22\n" "p 112 -10000 -32768 -40000 -22\n"
"0xcafebabe 0x0000beef\n" "0xcafebabe 0x0000beef\n"
"0x1 0x01 0x0001 0x00000001\n" "0x1 0x01 0x0001 0x00000001 0x0000000000000001\n"
"0x1 0x 1 0x 1 0x 1\n" "0x1 0x 1 0x 1 0x 1\n"
"42 42 0042 00000042\n" "42 42 0042 00000042\n"
"-42 -42 -042 -0000042\n" "-42 -42 -042 -0000042\n"
"42 42 42 42\n" "42 42 42 42\n"
"42 42 0042 00000042\n" "42 42 0042 00000042\n"
"255 42 abcdef 0x0000002a 42\n" "255 42 abcdef 0x0000002a 42\n"
"-1 4294967295 ffffffff\n" "-1 4294967295 ffffffffffffffff\n"
; ;
@ -73,15 +73,13 @@ void test_printk(void)
{ {
int count; int count;
printk("%lld %llu %llx",
1LL, -1ULL, -1ULL);
_old_char_out = __printk_get_hook(); _old_char_out = __printk_get_hook();
__printk_hook_install(ram_console_out); __printk_hook_install(ram_console_out);
printk("%zu %hhu %hu %u %lu %llu\n", stv, uc, usi, ui, ul, ull); printk("%zu %hhu %hu %u %lu %llu\n", stv, uc, usi, ui, ul, ull);
printk("%c %hhd %hd %d %ld %lld\n", c, c, ssi, si, sl, sll); printk("%c %hhd %hd %d %ld %lld\n", c, c, ssi, si, sl, sll);
printk("0x%x %p\n", hex, ptr); printk("0x%x %p\n", hex, ptr);
printk("0x%x 0x%02x 0x%04x 0x%08x\n", 1, 1, 1, 1); printk("0x%x 0x%02x 0x%04x 0x%08x 0x%016x\n", 1, 1, 1, 1, 1);
printk("0x%x 0x%2x 0x%4x 0x%8x\n", 1, 1, 1, 1); printk("0x%x 0x%2x 0x%4x 0x%8x\n", 1, 1, 1, 1);
printk("%d %02d %04d %08d\n", 42, 42, 42, 42); printk("%d %02d %04d %08d\n", 42, 42, 42, 42);
printk("%d %02d %04d %08d\n", -42, -42, -42, -42); printk("%d %02d %04d %08d\n", -42, -42, -42, -42);
@ -104,7 +102,7 @@ void test_printk(void)
count += snprintk(ram_console + count, sizeof(ram_console) - count, count += snprintk(ram_console + count, sizeof(ram_console) - count,
"0x%x %p\n", hex, ptr); "0x%x %p\n", hex, ptr);
count += snprintk(ram_console + count, sizeof(ram_console) - count, count += snprintk(ram_console + count, sizeof(ram_console) - count,
"0x%x 0x%02x 0x%04x 0x%08x\n", 1, 1, 1, 1); "0x%x 0x%02x 0x%04x 0x%08x 0x%016x\n", 1, 1, 1, 1, 1);
count += snprintk(ram_console + count, sizeof(ram_console) - count, count += snprintk(ram_console + count, sizeof(ram_console) - count,
"0x%x 0x%2x 0x%4x 0x%8x\n", 1, 1, 1, 1); "0x%x 0x%2x 0x%4x 0x%8x\n", 1, 1, 1, 1);
count += snprintk(ram_console + count, sizeof(ram_console) - count, count += snprintk(ram_console + count, sizeof(ram_console) - count,