diff options
author | Evan Green <evgreen@chromium.org> | 2019-07-19 16:20:45 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:36 +0000 |
commit | 0128582fe62b51a74a4c6c5a91e9c5118e70e376 (patch) | |
tree | 7d8d96c756da853b87d36497ba649b1fc8dad398 /common/printf.c | |
parent | a41fea6b7df1c83072140c0da9e07f09a8b032e4 (diff) | |
download | chrome-ec-0128582fe62b51a74a4c6c5a91e9c5118e70e376.tar.gz |
printf: Convert %T to %pT
In order to be more compliant to standards, and ultimately turn on
compile-time printf format validation, switch the non-standard %T
into %pT, which takes a pointer to a 64-bit timestamp as an argument.
For convenience, define PRINTF_TIMESTAMP_NOW, which will use the
current time as the timestamp value, rather than forcing everyone
to pass a pointer to get_time().val.
For a couple of instances, simply use CPRINTS instead.
BUG=chromium:984041
TEST=make -j buildall
BRANCH=None
Cq-Depend:chrome-internal:1473305
Change-Id: I83e45b55a95ea27256dc147544ae3f7e39acc5dd
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704216
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/printf.c')
-rw-r--r-- | common/printf.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/common/printf.c b/common/printf.c index f3b912b5c1..89ee004452 100644 --- a/common/printf.c +++ b/common/printf.c @@ -210,6 +210,8 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, v = va_arg(args, uint32_t); #else /* NO_UINT64_SUPPORT */ uint64_t v; + int ptrspec; + void *ptrval; /* Handle length */ if (c == 'l') { @@ -217,16 +219,37 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, c = *format++; } - /* Special-case: %T = current time */ - if (c == 'T') { - v = get_time().val; - flags |= PF_64BIT; -#ifdef CONFIG_CONSOLE_VERBOSE - precision = 6; -#else - precision = 3; - v /= 1000; -#endif + if (c == 'p') { + ptrspec = *format++; + ptrval = va_arg(args, void *); + /* %pT - print a timestamp. */ + if (ptrspec == 'T') { + flags |= PF_64BIT; + /* NULL uses the current time. */ + if (ptrval == NULL) + v = get_time().val; + else + v = *(uint64_t *)ptrval; + + if (IS_ENABLED( + CONFIG_CONSOLE_VERBOSE)) { + precision = 6; + } else { + precision = 3; + v /= 1000; + } + + } else if (ptrspec == 'P') { + /* Print a raw pointer. */ + v = (unsigned long)ptrval; + if (sizeof(unsigned long) == + sizeof(uint64_t)) + flags |= PF_64BIT; + + } else { + return EC_ERROR_INVAL; + } + } else if (flags & PF_64BIT) { v = va_arg(args, uint64_t); } else { |