From patchwork Tue Jul 4 13:56:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 9825071 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 79D29603B5 for ; Tue, 4 Jul 2017 14:08:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68A0A200F5 for ; Tue, 4 Jul 2017 14:08:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B5D9280B0; Tue, 4 Jul 2017 14:08:21 +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 lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9A9AC200F5 for ; Tue, 4 Jul 2017 14:08:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dSOV1-0000GB-Go; Tue, 04 Jul 2017 14:08:19 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dSOV1-0000G6-5f for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=CGRs8i2t8YnAlwmoMGlt/3heIkt/0T0sUgdGBCKAzTA=; b=jNKbp8XBrcDGEDiaNKkncvJss3jkgxntxNo66UlVPyQhGN20QupKOSaYY8qeFIbdejFbhsiOdfA+fvoInfryk6kw+qHRYVLG3qtEBdrkmnH+IINGWbywf+ZGBt0WMsL+GLTFfXZN864tNHJ2K3a8bRkNY2PLQiUD/BBEnTRjO3k=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=CGRs8i2t8YnAlwmoMGlt/3heIkt/0T0sUgdGBCKAzTA=; b=CccyrFV26cLMb5BroBk2efXhnDuFplagYmjaD/QAuBfXpOclZGauhl6Zh3fdRl0GtHpmIt0xEnZBEyeNDavC4L3mQlUheAxWIjL09HQpMKwwbJvAzkNkY+8L5c0yFw3MitKI+Vz/hQ1FZT2S6gfHDU0YhesGL9DMZkeBevPqF7k=; Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of infineon.com designates 217.10.52.105 as permitted sender) client-ip=217.10.52.105; envelope-from=alexander.steffen@infineon.com; helo=smtp11.infineon.com; Received: from smtp11.infineon.com ([217.10.52.105]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dSOV0-0000x2-3S for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1499177298; x=1530713298; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=v2zHkdHl9KWylrs1Sh0+2o4QYsXpYcGQ2EghOyRkkqw=; b=HcZwf5RCY+FgMbt3ab3TSK6ULzk3zv2aYK0Jn58klzuQ/RAL3/DJKyi7 e7iFKrwqleWFVjyoJlyX2iOKBAX8/bBMG4MeDOIvWLR8IX1FNtaNOFAKX Z2cTx71/KooA72BHaqeVdFP64R1xqEuMkOFp3rVRfc6JAKl34qtYvvmvc U=; X-SBRS: None Received: from unknown (HELO mucxv002.muc.infineon.com) ([172.23.11.17]) by smtp11.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 04 Jul 2017 15:57:05 +0200 Received: from MUCSE609.infineon.com (unknown [172.23.7.110]) by mucxv002.muc.infineon.com (Postfix) with ESMTPS for ; Tue, 4 Jul 2017 15:57:03 +0200 (CEST) Received: from MUCSE603.infineon.com (172.23.7.104) by MUCSE609.infineon.com (172.23.7.110) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:58 +0200 Received: from ABGN5CG4522MQD.eu.infineon.com (172.29.170.97) by MUCSE603.infineon.com (172.23.7.104) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:58 +0200 From: Alexander Steffen To: Date: Tue, 4 Jul 2017 15:56:47 +0200 Message-ID: <20170704135648.7360-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20170704135648.7360-1-Alexander.Steffen@infineon.com> References: <20170704135648.7360-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.29.170.97] X-ClientProxiedBy: MUCSE601.infineon.com (172.23.7.102) To MUCSE603.infineon.com (172.23.7.104) X-Headers-End: 1dSOV0-0000x2-3S Subject: [tpmdd-devel] [PATCH 2/3] tpm-chip: Return TPM error codes from auto_startup functions X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net 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 | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index a353b7a..f20fcb7 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -404,8 +404,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 3123a6e..4784ccc 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 f7f34b2a..0a64714 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -1074,7 +1074,8 @@ 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. + * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing + * a TPM error code. */ int tpm2_auto_startup(struct tpm_chip *chip) { @@ -1109,8 +1110,6 @@ int tpm2_auto_startup(struct tpm_chip *chip) rc = tpm2_get_cc_attrs_tbl(chip); out: - if (rc > 0) - rc = -ENODEV; return rc; }