Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host Command fixes #59783

Merged
merged 3 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static enum ec_host_cmd_status validate_handler(const struct ec_host_cmd_handler
return EC_HOST_CMD_INVALID_RESPONSE;
}

if (args->version > sizeof(handler->version_mask) ||
if (args->version >= NUM_BITS(handler->version_mask) ||
!(handler->version_mask & BIT(args->version))) {
return EC_HOST_CMD_INVALID_VERSION;
}
Expand Down Expand Up @@ -233,7 +233,6 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void *
/* The pointer to rx buffer is constant during communication */
struct ec_host_cmd_handler_args args = {
.output_buf = (uint8_t *)tx->buf + TX_HEADER_SIZE,
.output_buf_max = tx->len_max - TX_HEADER_SIZE,
.input_buf = rx->buf + RX_HEADER_SIZE,
.reserved = NULL,
};
Expand Down Expand Up @@ -266,6 +265,7 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void *
args.command = rx_header->cmd_id;
args.version = rx_header->cmd_ver;
args.input_buf_size = rx_header->data_len;
args.output_buf_max = tx->len_max - TX_HEADER_SIZE,
args.output_buf_size = 0;

status = validate_handler(found_handler, &args);
Expand All @@ -274,6 +274,12 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void *
continue;
}

/*
* Pre-emptively clear the entire response buffer so we do not
* have any left over contents from previous host commands.
*/
memset(args.output_buf, 0, args.output_buf_max);

status = found_handler->handler(&args);

ec_host_cmd_send_response(status, &args);
Expand Down
Loading