Skip to content

Commit d394ab5

Browse files
author
Tzung-Bi Shih
committed
platform/chrome: cros_ec_proto: handle empty payload in getting info legacy
cros_ec_get_proto_info_legacy() expects to receive sizeof(struct ec_response_hello) from send_command(). The payload is valid only if the return value is positive. Return -EPROTO if send_command() returns 0 in cros_ec_get_proto_info_legacy(). Reviewed-by: Guenter Roeck <[email protected]> Signed-off-by: Tzung-Bi Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cce5d55 commit d394ab5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
356356
struct cros_ec_command *msg;
357357
struct ec_params_hello *params;
358358
struct ec_response_hello *response;
359-
int ret;
359+
int ret, mapped;
360360

361361
ec_dev->proto_version = 2;
362362

@@ -377,12 +377,18 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
377377
goto exit;
378378
}
379379

380-
ret = cros_ec_map_error(msg->result);
381-
if (ret) {
380+
mapped = cros_ec_map_error(msg->result);
381+
if (mapped) {
382+
ret = mapped;
382383
dev_err(ec_dev->dev, "EC responded to v2 hello with error: %d\n", msg->result);
383384
goto exit;
384385
}
385386

387+
if (ret == 0) {
388+
ret = -EPROTO;
389+
goto exit;
390+
}
391+
386392
response = (struct ec_response_hello *)msg->data;
387393
if (response->out_data != 0xa1b2c3d4) {
388394
dev_err(ec_dev->dev,

0 commit comments

Comments
 (0)