From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21401C31E45 for ; Thu, 13 Jun 2019 16:13:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E443720665 for ; Thu, 13 Jun 2019 16:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560442394; bh=OlfFuwqkusPg47NaZV4i+qxupDmk6G6+k2SfXQaRtMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v6ZxkqZNi7UQVN7RgLRR9fPf4lEpOdclxnm+EaEd8DgJXmapW9jjfo143PfihiCM7 DX+a01gIIR9MvJT/a03/IpYwVmLyKB8TA6LDGxLxdrllqKBSe3/CVZ6cqoBpYgc3rp aalBMux/SC3B6YCRNtc/esPgHhFbGZkHxmZzAvk4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388348AbfFMQNN (ORCPT ); Thu, 13 Jun 2019 12:13:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731216AbfFMInC (ORCPT ); Thu, 13 Jun 2019 04:43:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ECD582063F; Thu, 13 Jun 2019 08:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560415381; bh=OlfFuwqkusPg47NaZV4i+qxupDmk6G6+k2SfXQaRtMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WWTmjUbE9h9G1FDGlXi0LusETsZhyhGq/4RejdYfvOtW5X+BzmgLKr4Rg1wjkJxDD PfKwIh538S0B1YX9tnww01DEbc4CLvFhbUL5Vz2NG1XtSFzoeMAHuAD/FqD08lT+ow vvFEPtpD5uf1AvSlvt33JiXkBeQyjTqSo/SxLpKs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Enrico Granata , Jett Rink , Enric Balletbo i Serra , Sasha Levin Subject: [PATCH 4.19 075/118] platform/chrome: cros_ec_proto: check for NULL transfer function Date: Thu, 13 Jun 2019 10:33:33 +0200 Message-Id: <20190613075648.247115542@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190613075643.642092651@linuxfoundation.org> References: <20190613075643.642092651@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 94d4e7af14a1170e34cf082d92e4c02de9e9fb88 ] 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 Reviewed-by: Jett Rink Signed-off-by: Enric Balletbo i Serra Signed-off-by: Sasha Levin --- drivers/platform/chrome/cros_ec_proto.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index e5d5b1adb5a9..ac784ac66ac3 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -67,6 +67,17 @@ static int send_command(struct cros_ec_device *ec_dev, else 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); if (msg->result == EC_RES_IN_PROGRESS) { int i; -- 2.20.1