From patchwork Fri Dec 8 18:46:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10103165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D607602A0 for ; Fri, 8 Dec 2017 18:53:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E02628697 for ; Fri, 8 Dec 2017 18:53:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3101528E40; Fri, 8 Dec 2017 18:53:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B438128697 for ; Fri, 8 Dec 2017 18:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752573AbdLHSxR (ORCPT ); Fri, 8 Dec 2017 13:53:17 -0500 Received: from smtp2.infineon.com ([217.10.52.18]:63432 "EHLO smtp2.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbdLHSxQ (ORCPT ); Fri, 8 Dec 2017 13:53:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1512759196; x=1544295196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=w+ziLvy2xwbdkUF9IkoGHzQy7mP590AUCTt7FhdyAP0=; b=apcYhBrdUl56zbR5vWl77DMJ1shr4FqSg4iV/2tHT2BqdXs1rfBHInwf fxuo8Y68h4jyfYa8C2sYwuLJlXagAOASC4LvI2gabr1gMau2LOcgDcgJl ySvGt3o9dm1Z6TaAHbGOpGH9NsAIfGkPFqRN3tsnWhvH1+KWAecxJZyTC c=; X-SBRS: None Received: from unknown (HELO mucxv001.muc.infineon.com) ([172.23.11.16]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Dec 2017 19:53:15 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv001.muc.infineon.com (Postfix) with ESMTPS; Fri, 8 Dec 2017 19:53:15 +0100 (CET) Received: from ABGN5CG4522MQD.eu.infineon.com (172.23.8.247) by MUCSE708.infineon.com (172.23.7.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.669.32; Fri, 8 Dec 2017 19:53:15 +0100 From: Alexander Steffen To: , , , CC: Alexander Steffen Subject: [RFC][PATCH 7/9] tpm_tis_spi: release CS line when wait state handling fails Date: Fri, 8 Dec 2017 19:46:56 +0100 Message-ID: <20171208184658.9588-8-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20171208184658.9588-1-Alexander.Steffen@infineon.com> References: <20171208184658.9588-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE706.infineon.com (172.23.7.80) To MUCSE708.infineon.com (172.23.7.82) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By setting cs_change=1 multiple messages are kept within the same transaction, i.e. the CS line is not released after the first message. This is fine during normal transactions, when the last message sets cs_change=0, so that the CS line is released at the end. But when transactions cannot be completed, e.g. when the wait state handling times out, the CS line is not released before leaving the function, because no message is sent with cs_change=0. This breaks future SPI transactions, so ensure that the CS line is correcly released in this error case by sending an empty message. Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- Note: I expect it to work that way, but have not tested it yet. drivers/char/tpm/tpm_tis_spi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c index 2758b41..2cc6aa9 100644 --- a/drivers/char/tpm/tpm_tis_spi.c +++ b/drivers/char/tpm/tpm_tis_spi.c @@ -101,6 +101,17 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, } if (i == TPM_RETRY) { + spi_xfer.tx_buf = NULL; + spi_xfer.rx_buf = NULL; + spi_xfer.len = 0; + spi_xfer.cs_change = 0; + + spi_message_init(&m); + spi_message_add_tail(&spi_xfer, &m); + ret = spi_sync_locked(phy->spi_device, &m); + if (ret < 0) + goto exit; + ret = -ETIMEDOUT; goto exit; }