From 3842121022bc7a9f30a879f9715ff9d416eae7ba Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Fri, 22 Nov 2019 08:52:23 -0700 Subject: host_command: clear any leftover data We want to ensure that the entire buffer we may be sending back to the host from the EC does not contain any data from previous host command responses. Clear the data in common code so all chips do not have to implement this functionality. BRANCH=none BUG=b:144878983,chromium:1026994 TEST=new unit test shows cleared data Change-Id: I93ad4d36923ba1bf171f740e94830640d3fde3b0 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1930931 --- common/host_command.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'common/host_command.c') diff --git a/common/host_command.c b/common/host_command.c index eff1fac56b..c3a207937e 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -681,6 +681,20 @@ uint16_t host_command_process(struct host_cmd_handler_args *args) if (hcdebug) host_command_debug_request(args); + /* + * Pre-emptively clear the entire response buffer so we do not + * have any left over contents from previous host commands. + * For example, this prevents the last portion of a char array buffer + * from containing data from the last host command if the string does + * not take the entire width of the char array buffer. + * + * Note that if request and response buffers pointed to the same memory + * location, then the chip implementation already needed to provide a + * request_temp buffer in which the request data was already copied + * by this point (see host_packet_receive function). + */ + memset(args->response, 0, args->response_max); + #ifdef CONFIG_HOSTCMD_PD if (args->command >= EC_CMD_PASSTHRU_OFFSET(1) && args->command <= EC_CMD_PASSTHRU_MAX(1)) { -- cgit v1.2.1