summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2022-03-10 13:29:27 +0100
committerCommit Bot <commit-bot@chromium.org>2022-03-18 14:20:56 +0000
commit1c08eb4b2663d0e2ad0ca5bc98a8369b793b816b (patch)
tree74c39a0c9bff4cc8f2695367cb8a3476dded4a97
parentb2bf76967bf2a96294aad933449bc0b3bfd12cce (diff)
downloadchrome-ec-1c08eb4b2663d0e2ad0ca5bc98a8369b793b816b.tar.gz
zephyr: emul: generate I2C error on too short TCPCI message
TCPCI should generate a FAULT_STATUS.I2CInterfaceError on transmitting too short SOP* message. BUG=b:223766685 BRANCH=none TEST=zmake configure --test test-drivers Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: Ife86d0581de01fb8980e58ecd675fcafa3e670ed Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3515941 Tested-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Tomasz Michalec <tmichalec@google.com>
-rw-r--r--zephyr/emul/tcpc/emul_tcpci.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c
index c16e99d4c4..c97d002edd 100644
--- a/zephyr/emul/tcpc/emul_tcpci.c
+++ b/zephyr/emul/tcpc/emul_tcpci.c
@@ -1171,6 +1171,7 @@ static void tcpci_emul_disable_pd_msg_delivery(const struct emul *emul)
* @param emul Pointer to TCPCI emulator
*
* @return 0 on success
+ * @return -EIO when sending SOP message with less than 2 bytes in TX buffer
*/
static int tcpci_emul_handle_transmit(const struct emul *emul)
{
@@ -1183,6 +1184,13 @@ static int tcpci_emul_handle_transmit(const struct emul *emul)
type = TCPC_REG_TRANSMIT_TYPE(data->write_data);
+ if (type < NUM_SOP_STAR_TYPES && data->tx_msg->cnt < 2) {
+ LOG_ERR("Transmitting too short message (%d)",
+ data->tx_msg->cnt);
+ tcpci_emul_set_i2c_interface_err(emul);
+ return -EIO;
+ }
+
if (data->partner && data->partner->transmit) {
data->partner->transmit(emul, data->partner, data->tx_msg, type,
TCPC_REG_TRANSMIT_RETRY(data->write_data));