diff options
author | Evan Green <evgreen@chromium.org> | 2019-08-01 11:20:14 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:41 +0000 |
commit | b63e2a87a75dce8941d087c8736c5a35544ab3b0 (patch) | |
tree | 32a4bfe24554a38c6ad30dcb38911796d2acea50 /driver/touchpad_st.c | |
parent | 60d66714d3b41d69942652650672fd5259815538 (diff) | |
download | chrome-ec-b63e2a87a75dce8941d087c8736c5a35544ab3b0.tar.gz |
printf: Convert %h to %ph
In order to make printf more standard, use %ph. Pass a pointer to
a struct describing the buffer, including its size. Add a convenience
macro so that conversion between the old style and new style is purely
mechanical. The old style of %h cannot be converted directly to %ph as-is
because the C standard doesn't allow flags, precision, or field width on
%p.
Ultimately the goal is to enable compile-time printf format checking.
This gets us one step closer to that.
BUG=chromium:984041
TEST=make -j buildall
BRANCH=None
Cq-Depend:chrome-internal:1559798,chrome-internal:1560598
Change-Id: I9c0ca124a048314c9b62d64bd55b36be55034e0e
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730605
Diffstat (limited to 'driver/touchpad_st.c')
-rw-r--r-- | driver/touchpad_st.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/driver/touchpad_st.c b/driver/touchpad_st.c index 5fbeeb45ea..d3381bd92c 100644 --- a/driver/touchpad_st.c +++ b/driver/touchpad_st.c @@ -600,15 +600,16 @@ static void dump_memory(void) (uint8_t *)&rx_buf, rx_len); for (i = 0; i < rx_len - ST_TP_DUMMY_BYTE; i += 32) { - CPRINTF("%.4h %.4h %.4h %.4h %.4h %.4h %.4h %.4h\n", - rx_buf.bytes + i + 4 * 0, - rx_buf.bytes + i + 4 * 1, - rx_buf.bytes + i + 4 * 2, - rx_buf.bytes + i + 4 * 3, - rx_buf.bytes + i + 4 * 4, - rx_buf.bytes + i + 4 * 5, - rx_buf.bytes + i + 4 * 6, - rx_buf.bytes + i + 4 * 7); + CPRINTF("%ph %ph %ph %ph " + "%ph %ph %ph %ph\n", + HEX_BUF(rx_buf.bytes + i + 4 * 0, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 1, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 2, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 3, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 4, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 5, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 6, 4), + HEX_BUF(rx_buf.bytes + i + 4 * 7, 4)); msleep(8); } } @@ -1264,7 +1265,7 @@ int touchpad_debug(const uint8_t *param, unsigned int param_size, *data_size = 8; st_tp_read_host_buffer_header(); memcpy(buf, rx_buf.bytes, *data_size); - CPRINTS("header: %.*h", *data_size, buf); + CPRINTS("header: %ph", HEX_BUF(buf, *data_size)); return EC_SUCCESS; case ST_TP_DEBUG_CMD_READ_EVENTS: num_events = st_tp_read_all_events(0); |