Commit d38b83d3 authored by Enrico Granata's avatar Enrico Granata Committed by Stefan Bader

platform/chrome: cros_ec_proto: check for NULL transfer function

BugLink: https://bugs.launchpad.net/bugs/1836666

[ Upstream commit 94d4e7af ]

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: default avatarEnrico Granata <egranata@chromium.org>
Reviewed-by: default avatarJett Rink <jettrink@chromium.org>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent b8db9798
...@@ -66,6 +66,17 @@ static int send_command(struct cros_ec_device *ec_dev, ...@@ -66,6 +66,17 @@ static int send_command(struct cros_ec_device *ec_dev,
else else
xfer_fxn = ec_dev->cmd_xfer; xfer_fxn = ec_dev->cmd_xfer;
if (!xfer_fxn) {
/*
* This error can happen if a communication error happened and
* the EC is trying to use protocol v2, on an underlying
* communication mechanism that does not support v2.
*/
dev_err_once(ec_dev->dev,
"missing EC transfer API, cannot send command\n");
return -EIO;
}
ret = (*xfer_fxn)(ec_dev, msg); ret = (*xfer_fxn)(ec_dev, msg);
if (msg->result == EC_RES_IN_PROGRESS) { if (msg->result == EC_RES_IN_PROGRESS) {
int i; int i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment