]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.4/platform-chrome-cros_ec_proto-check-for-null-transfe.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / platform-chrome-cros_ec_proto-check-for-null-transfe.patch
CommitLineData
cd033818
SL
1From 46d0633a1de591d48fa97b183dc6eaa0278e80d5 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 a0b8c8a8c323..5c285f2b3a65 100644
29--- a/drivers/platform/chrome/cros_ec_proto.c
30+++ b/drivers/platform/chrome/cros_ec_proto.c
31@@ -66,6 +66,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