]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - 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
1 From 46cb12e7892f73be3038993da8cd9419c8284a6a Mon Sep 17 00:00:00 2001
2 From: Enrico Granata <egranata@chromium.org>
3 Date: Wed, 3 Apr 2019 15:40:36 -0700
4 Subject: platform/chrome: cros_ec_proto: check for NULL transfer function
5
6 [ Upstream commit 94d4e7af14a1170e34cf082d92e4c02de9e9fb88 ]
7
8 As new transfer mechanisms are added to the EC codebase, they may
9 not support v2 of the EC protocol.
10
11 If the v3 initial handshake transfer fails, the kernel will try
12 and call cmd_xfer as a fallback. If v2 is not supported, cmd_xfer
13 will be NULL, and the code will end up causing a kernel panic.
14
15 Add a check for NULL before calling the transfer function, along
16 with a helpful comment explaining how one might end up in this
17 situation.
18
19 Signed-off-by: Enrico Granata <egranata@chromium.org>
20 Reviewed-by: Jett Rink <jettrink@chromium.org>
21 Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 ---
24 drivers/platform/chrome/cros_ec_proto.c | 11 +++++++++++
25 1 file changed, 11 insertions(+)
26
27 diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
28 index 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 --
50 2.20.1
51