]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.51/platform-chrome-cros_ec_proto-check-for-null-transfe.patch
Linux 4.19.51
[thirdparty/kernel/stable-queue.git] / releases / 4.19.51 / platform-chrome-cros_ec_proto-check-for-null-transfe.patch
CommitLineData
37554d48
SL
1From 46cb12e7892f73be3038993da8cd9419c8284a6a Mon Sep 17 00:00:00 2001
2From: Enrico Granata <egranata@chromium.org>
3Date: Wed, 3 Apr 2019 15:40:36 -0700
4Subject: platform/chrome: cros_ec_proto: check for NULL transfer function
5
6[ Upstream commit 94d4e7af14a1170e34cf082d92e4c02de9e9fb88 ]
7
8As new transfer mechanisms are added to the EC codebase, they may
9not support v2 of the EC protocol.
10
11If the v3 initial handshake transfer fails, the kernel will try
12and call cmd_xfer as a fallback. If v2 is not supported, cmd_xfer
13will be NULL, and the code will end up causing a kernel panic.
14
15Add a check for NULL before calling the transfer function, along
16with a helpful comment explaining how one might end up in this
17situation.
18
19Signed-off-by: Enrico Granata <egranata@chromium.org>
20Reviewed-by: Jett Rink <jettrink@chromium.org>
21Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
22Signed-off-by: Sasha Levin <sashal@kernel.org>
23---
24 drivers/platform/chrome/cros_ec_proto.c | 11 +++++++++++
25 1 file changed, 11 insertions(+)
26
27diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
28index e5d5b1adb5a9..ac784ac66ac3 100644
29--- a/drivers/platform/chrome/cros_ec_proto.c
30+++ b/drivers/platform/chrome/cros_ec_proto.c
31@@ -67,6 +67,17 @@ static int send_command(struct cros_ec_device *ec_dev,
32 else
33 xfer_fxn = ec_dev->cmd_xfer;
34
35+ if (!xfer_fxn) {
36+ /*
37+ * This error can happen if a communication error happened and
38+ * the EC is trying to use protocol v2, on an underlying
39+ * communication mechanism that does not support v2.
40+ */
41+ dev_err_once(ec_dev->dev,
42+ "missing EC transfer API, cannot send command\n");
43+ return -EIO;
44+ }
45+
46 ret = (*xfer_fxn)(ec_dev, msg);
47 if (msg->result == EC_RES_IN_PROGRESS) {
48 int i;
49--
502.20.1
51