From patchwork Mon Jun 5 17:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2861393vqr; Mon, 5 Jun 2023 11:03:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4fXucPKr7ZrxRPkEd8/HpdiMYqTyb/YZhuRLFYRnuab8HU7hmilbK+/3p5WDrcDasHRlGS X-Received: by 2002:a05:6a00:2353:b0:648:8c0d:6e4e with SMTP id j19-20020a056a00235300b006488c0d6e4emr433758pfj.19.1685988193391; Mon, 05 Jun 2023 11:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685988193; cv=none; d=google.com; s=arc-20160816; b=zFmsUBkMlB7UGVHTV3wvhKYWMnEmho1CtLgju2H56FNpeTxF9UIIN+fE0j051VZSlR EJ+cddOdYDt4/+Fd7NWO+Mb5yR2nmfBwWgO1qLSxlQgNfHZyqOxCf8TMz6dqQn2Rzfol 9RJrHiMBx5axsOTIUPl7cqt+WB6solnaql/9uLqA4J9rmtiWsb5yUINPwxSVab/ImaNo 06/i1HCzztnN86y1DXs/tTFXaBksHbEdSuWZN88zl1Ld6t43UdUjfL4xd1yA3+gGHrL7 KrPOffXQtIn2ZJwsnzZ3bVBo/KOZhKAbXJ+T6VqJz7xI8kuZ2o+kSI+BQjmBZ3Y2Js1y PSZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EqTJmYrZMev0F8vWNbuIMvFQRIJM9hTAtdrTRdNayhw=; b=TiLrNgXVRyIFE1FcfBS2TjS2NKub769QtuiHk9oRKPCE3zZDeL97P6gSzK9Dz6ACM+ u21pPM6t2B8nR7sHAP1S9C3yROYBso2VIngvuvcU0iC9O8jrrgOaMD2TcvR/sTqm3fzq 0kTbOiH9QM/bpA1frZDgW8ZrwheDnJWzVSb90BeqYKFo9oXtN29rFskgimbSAeJtsP6E K6x3CQcCA/jHrg7q5YYtauS/Dp6dHg0GoH9TTUO0eNwQZtjGvcmAFT8M79dnSCec9Tr2 vGn7VFOCN0d3rhz6jG4xjyLYCF3724oaopeBbFSGIDnNkW6/kUKMhmzIZ7ApVFfnedJv 7Y4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=nFQPneGt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a26-20020aa794ba000000b0064d2a385c1csi5665133pfl.252.2023.06.05.11.02.58; Mon, 05 Jun 2023 11:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=nFQPneGt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233511AbjFESAW (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjFESAM (ORCPT ); Mon, 5 Jun 2023 14:00:12 -0400 Received: from smtp11.infineon.com (smtp11.infineon.com [IPv6:2a00:18f0:1e00:4::5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC864F1; Mon, 5 Jun 2023 11:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988011; x=1717524011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=89MCpdG+JGXZTxJwkWPn/J+rl3u69O0nt8q8tvWyKNM=; b=nFQPneGteeYZdHM9WhK5PtnP5+kZPzwN56kRiYfX2VPlYvJFoRaMGQbS gl8ae5xwM4mdCLrulJEbOAQx0YEvdyi7mEJPgasRgaO8VvpsMBqsFB9Tx DEo9rELqEdS60rqlpEqxbzSZFIyvmQviag/ENB1L5w0QibbdP7YHqxU7v c=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="17446835" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="17446835" Received: from unknown (HELO MUCSE822.infineon.com) ([172.23.29.53]) by smtp11.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:09 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE822.infineon.com (172.23.29.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:09 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:08 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 2/4] tpm_tis: Move CRC check to generic send routine Date: Mon, 5 Jun 2023 19:59:57 +0200 Message-ID: <20230605175959.2131-3-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767886756145459630?= X-GMAIL-MSGID: =?utf-8?q?1767886756145459630?= The CRC functionality is initialized before tpm_tis_core, so it can be used on all code paths within the module. Therefore, move the CRC check to the generic send routine, that also contains all other checks for successful command transmission, so that all those checks are in one place. Also, this ensures that tpm_tis_ready is called when a CRC failure is detected, to clear the invalid data from the TPM, which did not happen previously. Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index aaaa136044ae..5ddaf24518be 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -466,6 +466,12 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) goto out_err; } + rc = tpm_tis_verify_crc(priv, len, buf); + if (rc < 0) { + dev_err(&chip->dev, "CRC mismatch for command.\n"); + goto out_err; + } + return 0; out_err: @@ -510,12 +516,6 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) if (rc < 0) return rc; - rc = tpm_tis_verify_crc(priv, len, buf); - if (rc < 0) { - dev_err(&chip->dev, "CRC mismatch for command.\n"); - return rc; - } - /* go and do it */ rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO); if (rc < 0)