From patchwork Tue Jun 13 18:02: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: 107515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp767935vqr; Tue, 13 Jun 2023 12:08:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rWJ50hzl+YvRitOe+qe8S2DF/DOMZvkkbY8KABbGHR3ulVjehr6kOcvfaGZ54wn6GLcEm X-Received: by 2002:a17:907:16a2:b0:978:73af:1bec with SMTP id hc34-20020a17090716a200b0097873af1becmr12367339ejc.33.1686683337384; Tue, 13 Jun 2023 12:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686683337; cv=none; d=google.com; s=arc-20160816; b=bs0EZ79zLMWigLtG45wsD2lu53OldLybuOAwBCkFWRbROEStGo5HmYsSN1gwDR0h+Q gPcGMeEf2moZr2isoDGrImLi3Ue8p2Au5Q5leCKd3mhlS2z1tRxp6aFahwqN9kjI1GuN l0kP75TR/yfnxmG7ZkUuKqTpw33oDjN7v8N7KNjFrgwtoZHQ/4nBWzhOPi/g9eXlbP2V IVk2L9vTEaTCBdOBB62wH9Cv+XrrticR4/AgonMAQWLF/6/ebV1WefwKhBHCGAYilnVA egu3CyxAUVYkoYEkOJVtxvEl72cpBYUEr9VXeVjjHvdDATZL3E0ufwYjnzcGRYKhu1en 4xnQ== 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=bdDPtBQcnuNviXiDBLtcMzAaWK9mfR4vTsXTkALHIxc=; b=GGfqf+oMWplzp7B1Jg05iPH+KSbyHFUnHuVLBYNZckUaEtdpLHrhzI9r+futMuSK7f +eq+lFiS48sn+vjY4D3Viy49IFj+M367piUbnLgUvAolW87n/PZeGkLlUiUlcoO0qjo9 aBFJmkFSLdbhmfeZUQIxXHvv54MCH6mLWpGOcUeiIG9Q1SU1sfWToocXRLhvR/uucxxV XOXXixKPLd1Mt8B2xj5YJZJzXlwbKLe1TDVgz+ZGgoCmvejOuGuWHtaQ6cOJvj+lJcpN uXlqOmznv+9odeZCNXhi0/7G8E8QrbLd51DvnH1UVx+pa69P3BtVhPZad/3tDhRfEiyn KV1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=JQ0jWuAd; 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 qc11-20020a170906d8ab00b0097896c31122si4238371ejb.663.2023.06.13.12.08.32; Tue, 13 Jun 2023 12:08:57 -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=JQ0jWuAd; 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 S239515AbjFMSDW (ORCPT + 99 others); Tue, 13 Jun 2023 14:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240084AbjFMSDU (ORCPT ); Tue, 13 Jun 2023 14:03:20 -0400 Received: from smtp11.infineon.com (smtp11.infineon.com [IPv6:2a00:18f0:1e00:4::5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3861E13E; Tue, 13 Jun 2023 11:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1686679399; x=1718215399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5pcn4JBKT2FT6yd1+VzPQHvpUKyuNh4EHo//3ud20mE=; b=JQ0jWuAdI90t7G7oOkkrKO4bSiUT81cJ7cfEYlKDst6nfaLQsAlgclCI nwzpEkNLVaK9AVhAx4s5xLZdYg9BpRuFS1LYZrQ50v+RgcivbV9iO5OXQ PaP6GGSK2u+MYRHbP/L76sTzt70UZWLPbS9Iplvg4cJqN3F0ixYLAe8UW 4=; X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="18551330" X-IronPort-AV: E=Sophos;i="6.00,240,1681164000"; d="scan'208";a="18551330" Received: from unknown (HELO MUCSE814.infineon.com) ([172.23.29.40]) by smtp11.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2023 20:03:17 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE814.infineon.com (172.23.29.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 13 Jun 2023 20:03:16 +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; Tue, 13 Jun 2023 20:03:16 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v3 2/4] tpm_tis: Move CRC check to generic send routine Date: Tue, 13 Jun 2023 20:02:57 +0200 Message-ID: <20230613180259.3525-3-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230613180259.3525-1-Alexander.Steffen@infineon.com> References: <20230613180259.3525-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE821.infineon.com (172.23.29.47) 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,URIBL_BLOCKED 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?1768615667119135206?= X-GMAIL-MSGID: =?utf-8?q?1768615667119135206?= 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)