Skip to content

Commit 94d4e7a

Browse files
Enrico GranataEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_proto: check for NULL transfer function
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol. If the v3 initial handshake transfer fails, the kernel will try and call cmd_xfer as a fallback. If v2 is not supported, cmd_xfer will be NULL, and the code will end up causing a kernel panic. Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation. Signed-off-by: Enrico Granata <[email protected]> Reviewed-by: Jett Rink <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent a2679b6 commit 94d4e7a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ static int send_command(struct cros_ec_device *ec_dev,
5656
else
5757
xfer_fxn = ec_dev->cmd_xfer;
5858

59+
if (!xfer_fxn) {
60+
/*
61+
* This error can happen if a communication error happened and
62+
* the EC is trying to use protocol v2, on an underlying
63+
* communication mechanism that does not support v2.
64+
*/
65+
dev_err_once(ec_dev->dev,
66+
"missing EC transfer API, cannot send command\n");
67+
return -EIO;
68+
}
69+
5970
ret = (*xfer_fxn)(ec_dev, msg);
6071
if (msg->result == EC_RES_IN_PROGRESS) {
6172
int i;

0 commit comments

Comments
 (0)