From 129c26685df2a045069cabf8e60fce5ba679e8c5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 6 Nov 2019 16:50:54 -0800 Subject: ec_commands: Force enum to be at least 16 bits If the values in the enum can fit in a byte, the compiler can optimize the size of the enum to a byte. However, our protocol requires 16 bits, so define a max enum value that forces at least 16 bits. BRANCH=none BUG=b:144056522 TEST=make buildall -j Change-Id: I119d990f2775d8b970ec0ec15df1e451fc5dc45d Signed-off-by: Tom Hughes Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1902679 Reviewed-by: Jack Rosenthal Reviewed-by: Jett Rink Reviewed-by: Daisuke Nojiri Commit-Queue: Jett Rink --- include/ec_commands.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/ec_commands.h b/include/ec_commands.h index 50b23f6ef3..29278ddebe 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -536,8 +536,7 @@ extern "C" { (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) /* - * Host command response codes (16-bit). Note that response codes should be - * stored in a uint16_t rather than directly in a value of this type. + * Host command response codes (16-bit). */ enum ec_status { EC_RES_SUCCESS = 0, @@ -561,7 +560,10 @@ enum ec_status { EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ -}; + + EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ +} __packed; +BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); /* * Host event codes. Note these are 1-based, not 0-based, because ACPI query -- cgit v1.2.1