From patchwork Wed Nov 13 08:00:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry Snitselaar X-Patchwork-Id: 11241313 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80C3B1515 for ; Wed, 13 Nov 2019 08:01:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B9A1207FC for ; Wed, 13 Nov 2019 08:01:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MzAhovt2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726138AbfKMIA7 (ORCPT ); Wed, 13 Nov 2019 03:00:59 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58765 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725976AbfKMIA7 (ORCPT ); Wed, 13 Nov 2019 03:00:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573632057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CMk5IBNgQTUKXm1UH2KRTJi2cKWC2WnWXM6M0NEqON4=; b=MzAhovt2G9YZSZ4XyffpYNPH7JlP+a4cFlsASdV0KMV7v9dmcjvmT1rireMSLTzoN5aI5M 4IjFOSEJRMqZi4GBTQuy8dGcFCnKU0dPEhCr2cqbVQqOR8y4zuMmPWat+3zYkR6wqw10Gg U/zC+B9DQqd0LNbWhBwMbjYL7fdwCwM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-DZfi_6wuNua0lcrnQv12BA-1; Wed, 13 Nov 2019 03:00:54 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C5D118B5F6A; Wed, 13 Nov 2019 08:00:52 +0000 (UTC) Received: from cantor.redhat.com (ovpn-116-198.phx2.redhat.com [10.3.116.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42F5C5D9E5; Wed, 13 Nov 2019 08:00:52 +0000 (UTC) From: Jerry Snitselaar To: linux-integrity@vger.kernel.org Cc: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] tpm: move TPM_CHIP_FLAG_HAVE_TIMEOUTS check Date: Wed, 13 Nov 2019 01:00:02 -0700 Message-Id: <20191113080002.14932-1-jsnitsel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: DZfi_6wuNua0lcrnQv12BA-1 X-Mimecast-Spam-Score: 0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Since tpm1_get_timeouts and tpm2_get_timeouts are now called directly by the auto startup code in addition to being called by tpm_get_timeouts, push the flag check down into the individual functions to avoid going through them again if they've already set the TPM_CHIP_FLAG_HAVE_TIMEOUTS flag. Cc: Peter Huewe Cc: Jarkko Sakkinen Cc: Jason Gunthorpe Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Fixes: d4a317563207 ("tpm: move tpm 1.x selftest code from tpm-interface.c tpm1-cmd.c") Fixes: 9db7fe187c54 ("tpm: factor out tpm_startup function") Signed-off-by: Jerry Snitselaar --- drivers/char/tpm/tpm-interface.c | 3 --- drivers/char/tpm/tpm1-cmd.c | 3 +++ drivers/char/tpm/tpm2-cmd.c | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index d7a3888ad80f..3c9e14981ce6 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -237,9 +237,6 @@ EXPORT_SYMBOL_GPL(tpm_transmit_cmd); int tpm_get_timeouts(struct tpm_chip *chip) { - if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) - return 0; - if (chip->flags & TPM_CHIP_FLAG_TPM2) return tpm2_get_timeouts(chip); else diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index 149e953ca369..5330b32d1469 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -345,6 +345,9 @@ int tpm1_get_timeouts(struct tpm_chip *chip) unsigned long timeout_old[4], timeout_chip[4], timeout_eff[4]; ssize_t rc; + if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) + return 0; + rc = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, NULL, sizeof(cap.timeout)); if (rc == TPM_ERR_INVALID_POSTINIT) { diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index ba9acae83bff..55d96be86ed8 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -38,6 +38,9 @@ static struct tpm2_hash tpm2_hash_map[] = { int tpm2_get_timeouts(struct tpm_chip *chip) { + if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) + return 0; + /* Fixed timeouts for TPM2 */ chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); chip->timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);