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.8 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,USER_AGENT_GIT autolearn=unavailable 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 A9345C43613 for ; Thu, 20 Jun 2019 18:32:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 79EBA206BF for ; Thu, 20 Jun 2019 18:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561055524; bh=eDOu6ShsslUalUYJi3yKS4My3OeSY/qmqS79F4rru9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=seVVPKICQQ0EaWgvjJehYlJM3Sqhvf7HjGOdWqezsQboRWJXh1jpyMC/KbKf3J4yY 95IQzhY94jXL1fu1PNrKbrtGgbCp76eAFKB8twQ4m+qrStBaMVau2JFiOyhbqNxi7u zRVGAvgADaE8/R6DdyuEK4YcSf/Rzqz8V2TrGsAA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbfFTR6x (ORCPT ); Thu, 20 Jun 2019 13:58:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45702 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbfFTR6v (ORCPT ); Thu, 20 Jun 2019 13:58:51 -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 7A03521479; Thu, 20 Jun 2019 17:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561053531; bh=eDOu6ShsslUalUYJi3yKS4My3OeSY/qmqS79F4rru9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rf+3IAIN50OCK2jCdJXd6ZynLlYCJHK1VdJ8XtChmrvls08rDy29lL3ONmnq8GGvb hBlM2RoDDuErf5UeCluuhNofIaoZTGgvLnoHzqaGLcMmpbyMNIQxvASfVJGp6QMSV0 TU4JxIbJQ1nTBniCWogX/rNQnmJk31P4986jT3eg= 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.4 21/84] platform/chrome: cros_ec_proto: check for NULL transfer function Date: Thu, 20 Jun 2019 19:56:18 +0200 Message-Id: <20190620174340.804372470@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174337.538228162@linuxfoundation.org> References: <20190620174337.538228162@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 a0b8c8a8c323..5c285f2b3a65 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -66,6 +66,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