Re: [PATCH v4] platform/chrome: cros_ec_proto: Fix deferred response

From: Tzung-Bi Shih

Date: Fri Aug 28 2026 - 01:31:14 EST


On Thu, Aug 27, 2026 at 12:05:11PM -0600, Rob Barnes wrote:
> - Send patch using git-send-email via Google Mail Relay to prevent MTA line-wrapping (Tzung-Bi).

The patch can be applied via `git am` after the fixing. However, KUnit test
emits errors after applying the patch:

$ ./tools/testing/kunit/kunit.py run \
--arch=x86_64 \
--kconfig_add CONFIG_CHROME_PLATFORMS=y \
--kconfig_add CONFIG_CROS_EC=y \
cros_ec*

> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
...
> +static void cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes(struct kunit *test)
> +{
> + struct cros_ec_proto_test_priv *priv = test->priv;
> + struct cros_ec_device *ec_dev = &priv->ec_dev;
> + struct ec_xfer_mock *mock;
> + u8 resp_data[4] = {0x11, 0x22, 0x33, 0x44};
> + struct {
> + struct cros_ec_command msg;
> + u8 data[4];
> + } buf;
> + struct cros_ec_command *msg = &buf.msg;
> + int ret;
> +
> + memset(&buf, 0, sizeof(buf));
> + msg->version = 1;
> + msg->command = 0x1234;
> + msg->outsize = 2;

It needs to set `ec_dev->max_request` before it can send the payload. Given
the test doesn't verify the output payload, just removing the assignment of
`msg->outsize` and using default value 0 could be the simplest fix.
Otherwise:

cros_ec_proto_test: request of size 2 is too big (max: 0)
# cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes:
Expected ret == 4, but
ret == -90 (0xffffffffffffffa6)

> + msg->insize = sizeof(buf.data);

Similar here, it needs to set `ec_dev->max_response` before it can receive
payload (cros_ec_cmd_xfer() clamps it). Otherwise:

# cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes:
Expected msg->insize == sizeof(buf.data), but
msg->insize == 0 (0x0)
sizeof(buf.data) == 4 (0x4)

> + ret = cros_ec_cmd_xfer(ec_dev, msg);
> + KUNIT_EXPECT_EQ(test, ret, 4);
> + KUNIT_EXPECT_EQ(test, msg->result, EC_RES_SUCCESS);
> + KUNIT_EXPECT_EQ(test, msg->command, 0x1234);
> + KUNIT_EXPECT_EQ(test, msg->outsize, 2);

Following the above suggestion, this needs to be dropped.

> +static void cros_ec_proto_test_cmd_xfer_in_progress_payload_gt4bytes(struct kunit *test)
> +{
> + struct cros_ec_proto_test_priv *priv = test->priv;
> + struct cros_ec_device *ec_dev = &priv->ec_dev;
> + struct ec_xfer_mock *mock;
> + u8 resp_data[16];
> + struct {
> + struct cros_ec_command msg;
> + u8 data[16];
> + } buf;
> + struct cros_ec_command *msg = &buf.msg;
> + int ret, i;
> +
> + for (i = 0; i < sizeof(resp_data); ++i)
> + resp_data[i] = (u8)(i + 1);
> +
> + memset(&buf, 0, sizeof(buf));
> + msg->version = 0;
> + msg->command = 0x5678;
> + msg->insize = sizeof(buf.data);
> +
> + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock;

Same here:

ec_dev->max_response = sizeof(buf.data);