summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Andersen <jeffandersen@google.com>2017-05-23 17:12:25 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-05-25 04:27:41 -0700
commitcf81f80c4f1fe9294848d56c75e68699e85d8e03 (patch)
tree0d459169860b2e0a3eff13b5147cecda16388e54
parent4fd6f23101d1f7aed89568e5f4cacb99b5ae4710 (diff)
downloadchrome-ec-cf81f80c4f1fe9294848d56c75e68699e85d8e03.tar.gz
Enable two-byte responses from host command handlers.
Previously, result codes were being stored as `enum ec_status` values. The compiler was forcing this value to only be one byte large, since that's all that was necessary to represent all the values of that enum. This change fixes this bug by switching result code variable types from `enum ec_status` to `uint16_t`. BRANCH=none BUG=none TEST=make buildall -j Change-Id: Iacdca51dc6c1de677d2fbb59ad6dd2572d21ea7f Reviewed-on: https://chromium-review.googlesource.com/513609 Commit-Ready: Jeff Andersen <jeffandersen@google.com> Tested-by: Jeff Andersen <jeffandersen@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/host_command.c4
-rw-r--r--include/ec_commands.h8
-rw-r--r--include/host_command.h21
3 files changed, 24 insertions, 9 deletions
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
/**