Skip to content

Commit

Permalink
mgmt: ec_host_cmd: update checking the handler buffer
Browse files Browse the repository at this point in the history
The general handler may provide buffers for a backend. Use ranges to
check if the provided buffer is used, because the backend may shift the
beginning of the buffer to make space for preamble.

Signed-off-by: Dawid Niedzwiecki <[email protected]>
  • Loading branch information
niedzwiecki-dawid committed Apr 26, 2023
1 parent e68f0a1 commit e10d1e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 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 @@ -256,8 +256,15 @@ int ec_host_cmd_init(struct ec_host_cmd_backend *backend)
return -EIO;
}

if ((handler_tx_buf && (handler_tx_buf != hc->tx.buf)) ||
(handler_rx_buf && (handler_rx_buf != hc->rx_ctx.buf))) {
/* Check if a backend provided buffer. The buffer pointer can be shifted within the buffer
* to make space for preamble.
*/
if ((handler_tx_buf && ((handler_tx_buf > (uint8_t *)hc->tx.buf) &&
((handler_tx_buf + CONFIG_EC_HOST_CMD_HANDLER_TX_BUFFER_SIZE) >
(uint8_t *)hc->tx.buf))) ||
(handler_rx_buf &&
((handler_rx_buf > hc->rx_ctx.buf) &&
((handler_rx_buf + CONFIG_EC_HOST_CMD_HANDLER_RX_BUFFER_SIZE) > hc->rx_ctx.buf)))) {
LOG_WRN("Host Command handler provided unused buffer");
}

Expand Down

0 comments on commit e10d1e9

Please sign in to comment.