summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEvan Green <evgreen@chromium.org>2019-07-19 16:20:45 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-05 00:47:36 +0000
commit0128582fe62b51a74a4c6c5a91e9c5118e70e376 (patch)
tree7d8d96c756da853b87d36497ba649b1fc8dad398 /common
parenta41fea6b7df1c83072140c0da9e07f09a8b032e4 (diff)
downloadchrome-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')
-rw-r--r--common/acpi.c3
-rw-r--r--common/battery.c2
-rw-r--r--common/capsense.c3
-rw-r--r--common/console_output.c2
-rw-r--r--common/host_command.c2
-rw-r--r--common/keyboard_scan.c4
-rw-r--r--common/lb_common.c2
-rw-r--r--common/motion_sense.c3
-rw-r--r--common/port80.c3
-rw-r--r--common/printf.c43
10 files changed, 47 insertions, 20 deletions
diff --git a/common/acpi.c b/common/acpi.c
index 68134a86e0..87e9c4fd27 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -313,7 +313,8 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
* does a lot of keyboard backlights and it scrolls the
* debug console.
*/
- CPRINTF("\r[%T ACPI kblight %d]", data);
+ CPRINTF("\r[%pT ACPI kblight %d]",
+ PRINTF_TIMESTAMP_NOW, data);
kblight_set(data);
break;
#endif
diff --git a/common/battery.c b/common/battery.c
index 7b6c3ee5bd..67d08b4150 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -350,7 +350,7 @@ DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cutoff,
static void check_pending_cutoff(void)
{
if (battery_cutoff_state == BATTERY_CUTOFF_STATE_PENDING) {
- CPRINTF("[%T Cutting off battery in %d second(s)]\n",
+ CPRINTS("Cutting off battery in %d second(s)",
CONFIG_BATTERY_CUTOFF_DELAY_US / SECOND);
hook_call_deferred(&pending_cutoff_deferred_data,
CONFIG_BATTERY_CUTOFF_DELAY_US);
diff --git a/common/capsense.c b/common/capsense.c
index 30ce34ebce..b2413ac61f 100644
--- a/common/capsense.c
+++ b/common/capsense.c
@@ -52,7 +52,8 @@ static void capsense_change_deferred(void)
new_val = capsense_read_bitmask();
if (new_val != cur_val) {
- CPRINTF("[%T capsense 0x%02x: ", new_val);
+ CPRINTF("[%pT capsense 0x%02x: ",
+ PRINTF_TIMESTAMP_NOW, new_val);
for (i = 0; i < CAPSENSE_MASK_BITS; i++) {
/* See what changed */
n = (new_val >> i) & 0x01;
diff --git a/common/console_output.c b/common/console_output.c
index b184ffd2be..86072d9b62 100644
--- a/common/console_output.c
+++ b/common/console_output.c
@@ -89,7 +89,7 @@ int cprints(enum console_channel channel, const char *format, ...)
return EC_SUCCESS;
#endif
- rv = cprintf(channel, "[%T ");
+ rv = cprintf(channel, "[%pT ", PRINTF_TIMESTAMP_NOW);
va_start(args, format);
r = uart_vprintf(format, args);
diff --git a/common/host_command.c b/common/host_command.c
index 9e14156c6e..be178f7b6c 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -604,7 +604,7 @@ static void dump_host_command_suppressed(int force)
if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
return;
- CPRINTF("[%T HC Suppressed:");
+ CPRINTF("[%pT HC Suppressed:", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
CPRINTF(" 0x%x=%d", hc_suppressed_cmd[i], hc_suppressed_cnt[i]);
hc_suppressed_cnt[i] = 0;
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c
index b4dd719784..7f7d44ceec 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -151,7 +151,7 @@ static void print_state(const uint8_t *state, const char *msg)
{
int c;
- CPRINTF("[%T KB %s:", msg);
+ CPRINTF("[%pT KB %s:", PRINTF_TIMESTAMP_NOW, msg);
for (c = 0; c < keyboard_cols; c++) {
if (state[c])
CPRINTF(" %02x", state[c]);
@@ -529,7 +529,7 @@ static int check_keys_changed(uint8_t *state)
#ifdef CONFIG_KEYBOARD_PRINT_SCAN_TIMES
/* Print delta times from now back to each previous scan */
- CPRINTF("[%T kb deltaT");
+ CPRINTF("[%pT kb deltaT", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < SCAN_TIME_COUNT; i++) {
int tnew = scan_time[
(SCAN_TIME_COUNT + scan_time_index - i) %
diff --git a/common/lb_common.c b/common/lb_common.c
index 93f01389b4..08783997fa 100644
--- a/common/lb_common.c
+++ b/common/lb_common.c
@@ -288,7 +288,7 @@ void lb_init(int use_lock)
{
int i;
- CPRINTF("[%T LB_init_vals ");
+ CPRINTF("[%pT LB_init_vals ", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < ARRAY_SIZE(init_vals); i++) {
CPRINTF("%c", '0' + i % 10);
if (use_lock)
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 7f34af1fc7..ef9cdef185 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -877,7 +877,8 @@ void motion_sense_task(void *u)
#endif
#ifdef CONFIG_CMD_ACCEL_INFO
if (accel_disp) {
- CPRINTF("[%T event 0x%08x ", event);
+ CPRINTF("[%pT event 0x%08x ",
+ PRINTF_TIMESTAMP_NOW, event);
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
CPRINTF("%s=%-5d, %-5d, %-5d ", sensor->name,
diff --git a/common/port80.c b/common/port80.c
index 7bb708e964..52264cc446 100644
--- a/common/port80.c
+++ b/common/port80.c
@@ -53,7 +53,8 @@ void port_80_write(int data)
* coming from the host.
*/
if (print_in_int)
- CPRINTF("%c[%T Port 80: 0x%02x]", scroll ? '\n' : '\r', data);
+ CPRINTF("%c[%pT Port 80: 0x%02x]",
+ scroll ? '\n' : '\r', PRINTF_TIMESTAMP_NOW, data);
else if (data < 0x100)
hook_call_deferred(&port80_dump_buffer_data, 4 * SECOND);
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 {