From patchwork Thu Dec 14 16:06:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10112615 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 2A35E60327 for ; Thu, 14 Dec 2017 16:06:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BDE6299EB for ; Thu, 14 Dec 2017 16:06:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10B7E29B06; Thu, 14 Dec 2017 16:06:52 +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 B2901299EB for ; Thu, 14 Dec 2017 16:06:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753343AbdLNQGv (ORCPT ); Thu, 14 Dec 2017 11:06:51 -0500 Received: from smtp2.infineon.com ([217.10.52.18]:56611 "EHLO smtp2.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752944AbdLNQGv (ORCPT ); Thu, 14 Dec 2017 11:06:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1513267610; x=1544803610; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nND09zyM2jfp4FMqs3JeLM46Xb7Z9KS0wf8ictAjZZc=; b=UhVnHo9gMkowrgnlTwU1YEXUoKFfTAJljzHamprRP2BZ7T8IiV1JgyKF yBb43YDxpPav2k5OAoTZSMIaWeGV2mpABbtmW5pbBJyVuI6neKoK/Gij5 5Z5cTOesUVK7/BQdX2O9gWKpkdim5Zuy1PpC+OCsmT4GZiAqncZs6LgeY M=; X-SBRS: None Received: from unknown (HELO mucxv003.muc.infineon.com) ([172.23.11.20]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 14 Dec 2017 17:06:50 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv003.muc.infineon.com (Postfix) with ESMTPS; Thu, 14 Dec 2017 17:06:50 +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; Thu, 14 Dec 2017 17:06:47 +0100 From: Alexander Steffen To: , CC: Alexander Steffen Subject: [RFC][PATCH 2/3] tpm-chip: Return TPM error codes from auto_startup functions Date: Thu, 14 Dec 2017 17:06:13 +0100 Message-ID: <20171214160614.11808-3-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20171214160614.11808-1-Alexander.Steffen@infineon.com> References: <20171214160614.11808-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE705.infineon.com (172.23.7.79) 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 The auto_startup functions for TPM1 and TPM2 convert all TPM error codes to ENODEV on exit. But since there is only one caller for those functions, this code can be consolidated within the caller. Additionally, this allows the caller to distinguish between a TPM being present (but returning error responses for some commands) and no TPM being present (or the TPM malfunctioning completely). Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm-chip.c | 4 +++- drivers/char/tpm/tpm-interface.c | 6 ++---- drivers/char/tpm/tpm2-cmd.c | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 25ebe49..9cbe1ef 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -398,8 +398,10 @@ int tpm_chip_register(struct tpm_chip *chip) rc = tpm2_auto_startup(chip); else rc = tpm1_auto_startup(chip); - if (rc) + if (rc < 0) return rc; + else if (rc > 0) + return -ENODEV; } tpm_sysfs_add_device(chip); diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index ebe0a1d..38e85ac 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -997,7 +997,8 @@ EXPORT_SYMBOL_GPL(tpm_do_selftest); * sequence * @chip: TPM chip to use * - * Returns 0 on success, < 0 in case of fatal error. + * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing + * a TPM error code. */ int tpm1_auto_startup(struct tpm_chip *chip) { @@ -1012,10 +1013,7 @@ int tpm1_auto_startup(struct tpm_chip *chip) goto out; } - return rc; out: - if (rc > 0) - rc = -ENODEV; return rc; } diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index f40d206..6cda355 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -1045,7 +1045,7 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip) * sequence * @chip: TPM chip to use * - * Returns 0 on success, < 0 in case of fatal error. + * Return: Same as with tpm_transmit_cmd. */ int tpm2_auto_startup(struct tpm_chip *chip) { @@ -1080,8 +1080,6 @@ int tpm2_auto_startup(struct tpm_chip *chip) rc = tpm2_get_cc_attrs_tbl(chip); out: - if (rc > 0) - rc = -ENODEV; return rc; }