diff --git a/common/host_command.c b/common/host_command.c index e82887738e..3578efc36f 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -599,7 +599,7 @@ static void host_command_debug_request(struct host_cmd_handler_args *args) CPRINTS("HC 0x%02x", args->command); } -enum ec_status host_command_process(struct host_cmd_handler_args *args) +uint16_t host_command_process(struct host_cmd_handler_args *args) { const struct host_command *cmd; int rv; @@ -854,7 +854,7 @@ static int command_host_command(int argc, char **argv) { struct host_cmd_handler_args args; char *cmd_params; - enum ec_status res; + uint16_t res; char *e; int rv; diff --git a/include/ec_commands.h b/include/ec_commands.h index 4ef579af65..40fbf0403b 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -460,7 +460,9 @@ #define EC_LPC_STATUS_BUSY_MASK \ (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) -/* Host command response codes */ +/* 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. + */ enum ec_status { EC_RES_SUCCESS = 0, EC_RES_INVALID_COMMAND = 1, @@ -477,8 +479,8 @@ enum ec_status { EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ - EC_RES_BUS_ERROR = 15, /* Communications bus error */ - EC_RES_BUSY = 16 /* Up but too busy. Should retry */ + EC_RES_BUS_ERROR = 15, /* Communications bus error */ + EC_RES_BUSY = 16 /* Up but too busy. Should retry */ }; /* diff --git a/include/host_command.h b/include/host_command.h index 02c9b07915..50466dc61d 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -48,8 +48,13 @@ struct host_cmd_handler_args { * command execution is complete. The driver may still override this * when sending the response back to the host if it detects an error * in the response or in its own operation. + * + * Note that while this holds an ec_status enum, we are intentionally + * representing this field as a uint16_t, to prevent issues related to + * compiler optimizations affecting the range of values representable + * by this field. */ - enum ec_status result; + uint16_t result; }; /* Args for host packet handler */ @@ -95,8 +100,13 @@ struct host_packet { * Error from driver; if this is non-zero, host command handler will * return a properly formatted error response packet rather than * calling a command handler. + * + * Note that while this holds an ec_status enum, we are intentionally + * representing this field as a uint16_t, to prevent issues related to + * compiler optimizations affecting the range of values representable + * by this field. */ - enum ec_status driver_result; + uint16_t driver_result; }; /* Host command */ @@ -127,9 +137,12 @@ uint8_t *host_get_memmap(int offset); * Process a host command and return its response * * @param args Command handler args - * @return resulting status + * @return resulting status. Note that while this returns an ec_status enum, we + * are intentionally specifying the return type as a uint16_t, to prevent issues + * related to compiler optimizations affecting the range of values returnable + * from this function. */ -enum ec_status host_command_process(struct host_cmd_handler_args *args); +uint16_t host_command_process(struct host_cmd_handler_args *args); #ifdef CONFIG_HOSTCMD_EVENTS /**