Skip to content

Commit fc8cacf

Browse files
computersforpeaceEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_proto: check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK
As with cros_ec_cmd_xfer_status(), etc., it's not enough to simply check for the return status of send_command() -- that only covers transport or other similarly-fatal errors. One must also check the ->result field, to see whether the command really succeeded. If not, we can't use the data it returns. The caller of cros_ec_get_host_event_wake_mask() ignores this, and so for example, on EC's where the command is not implemented, we're using junk (or in practice, all zeros) for our wake-mask. We should be using a non-zero default (currently, it's supposed to be all-1's). Fix this by checking the ->result field and returning -EPROTO for errors. I might label this as fixing commit 29d99b9 ("cros_ec: Don't signal wake event for non-wake host events"), except that this fix alone actually may make things worse, as it now allows for a lot more spurious wakeups. The patch "platform/chrome: cros_ec_proto: ignore battery/AC wakeups on old ECs" helps to mitigate this. Signed-off-by: Brian Norris <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent c214e56 commit fc8cacf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev,
208208
msg->insize = sizeof(*r);
209209

210210
ret = send_command(ec_dev, msg);
211+
if (ret >= 0) {
212+
if (msg->result == EC_RES_INVALID_COMMAND)
213+
return -EOPNOTSUPP;
214+
if (msg->result != EC_RES_SUCCESS)
215+
return -EPROTO;
216+
}
211217
if (ret > 0) {
212218
r = (struct ec_response_host_event_mask *)msg->data;
213219
*mask = r->mask;
@@ -488,6 +494,13 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
488494
BIT(EC_HOST_EVENT_BATTERY_CRITICAL) |
489495
BIT(EC_HOST_EVENT_PD_MCU) |
490496
BIT(EC_HOST_EVENT_BATTERY_STATUS));
497+
/*
498+
* Old ECs may not support this command. Complain about all
499+
* other errors.
500+
*/
501+
if (ret != -EOPNOTSUPP)
502+
dev_err(ec_dev->dev,
503+
"failed to retrieve wake mask: %d\n", ret);
491504
}
492505

493506
ret = 0;

0 commit comments

Comments
 (0)