From e10d1e92ff63b6d411347d76b320298d0c50db64 Mon Sep 17 00:00:00 2001 From: Dawid Niedzwiecki Date: Wed, 26 Apr 2023 11:31:09 +0000 Subject: [PATCH] mgmt: ec_host_cmd: update checking the handler buffer 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 --- subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c index 0b488a0ef8aef34..3d2cc1d56472e06 100644 --- a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c +++ b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c @@ -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"); }