diff options
author | Evan Green <evgreen@chromium.org> | 2019-08-02 14:32:24 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:44 +0000 |
commit | a1216326c5d58af300b7c6f24c8597a232ced131 (patch) | |
tree | d151d7b7eb59ce8213cfb450b2dfc7379f817590 /driver/temp_sensor/adt7481.c | |
parent | b63e2a87a75dce8941d087c8736c5a35544ab3b0 (diff) | |
download | chrome-ec-a1216326c5d58af300b7c6f24c8597a232ced131.tar.gz |
printf: Convert %b to %pb
In order to turn on compile-time printf format checking,
non-standard specifiers like %b (binary) must be removed. Convert
that into %pb, which takes a pointer to a structure containing the
value to print, and how many bits to print. Use the convenience
macro BINARY_VALUE() to package these values up into a struct whose
pointer is passed to printf().
Technically this is slightly more limited functionality than we used
to support given all the possible flags, field width, and precision.
However every existing instance in our codebase was using %0NNb, where
NN is some number. If more variants are needed, the parameters structure
can be expanded in the future.
BUG=chromium:984041
TEST=make -j buildall
BRANCH=None
Change-Id: I8ef995dcf97af688fbca98ab6ff59b84092b69e3
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733100
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver/temp_sensor/adt7481.c')
-rw-r--r-- | driver/temp_sensor/adt7481.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/driver/temp_sensor/adt7481.c b/driver/temp_sensor/adt7481.c index df6ff4bb7c..cbd32e5cd5 100644 --- a/driver/temp_sensor/adt7481.c +++ b/driver/temp_sensor/adt7481.c @@ -248,16 +248,16 @@ static int print_status(void) ccprintf("\n"); if (raw_read8(ADT7481_STATUS1_R, &value) == EC_SUCCESS) - ccprintf("STATUS1: %08b\n", value); + ccprintf("STATUS1: %pb\n", BINARY_VALUE(value, 8)); if (raw_read8(ADT7481_STATUS2_R, &value) == EC_SUCCESS) - ccprintf("STATUS2: %08b\n", value); + ccprintf("STATUS2: %pb\n", BINARY_VALUE(value, 8)); if (raw_read8(ADT7481_CONFIGURATION1_R, &value) == EC_SUCCESS) - ccprintf("CONFIG1: %08b\n", value); + ccprintf("CONFIG1: %pb\n", BINARY_VALUE(value, 8)); if (raw_read8(ADT7481_CONFIGURATION2, &value) == EC_SUCCESS) - ccprintf("CONFIG2: %08b\n", value); + ccprintf("CONFIG2: %pb\n", BINARY_VALUE(value, 8)); return EC_SUCCESS; } @@ -307,7 +307,8 @@ static int command_adt7481(int argc, char **argv) rv = raw_read8(offset, &data); if (rv < 0) return rv; - ccprintf("Byte at offset 0x%02x is %08b\n", offset, data); + ccprintf("Byte at offset 0x%02x is %pb\n", + offset, BINARY_VALUE(data, 8)); return rv; } |