From patchwork Tue Aug 30 01:28:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9304703 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 A15396077C for ; Tue, 30 Aug 2016 01:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 833DD28A5E for ; Tue, 30 Aug 2016 01:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77D7E28A64; Tue, 30 Aug 2016 01:28:47 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 73ABC28A5E for ; Tue, 30 Aug 2016 01:28:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1beXr2-00066Y-Uk; Tue, 30 Aug 2016 01:28:44 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1beXr1-00066S-Ho for tpmdd-devel@lists.sourceforge.net; Tue, 30 Aug 2016 01:28:43 +0000 X-ACL-Warn: Received: from mga07.intel.com ([134.134.136.100]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1beXqz-0008EP-W5 for tpmdd-devel@lists.sourceforge.net; Tue, 30 Aug 2016 01:28:43 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 29 Aug 2016 18:28:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,253,1470726000"; d="scan'208";a="754847993" Received: from ashamay-mobl.ger.corp.intel.com (HELO localhost) ([10.252.28.169]) by FMSMGA003.fm.intel.com with ESMTP; 29 Aug 2016 18:28:33 -0700 From: Jarkko Sakkinen To: Peter Huewe Date: Tue, 30 Aug 2016 04:28:17 +0300 Message-Id: <1472520498-24173-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.4 X-Headers-End: 1beXqz-0008EP-W5 Cc: "moderated list:TPM DEVICE DRIVER" , open list Subject: [tpmdd-devel] [PATCH] tpm: fix invalid constant expressions in tpm.h X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP The enums tpm_capabilities and tpm_sub_capabilities do not contain legit constant expressions. This commit makes cap_id a separate parameter in order to provide less confusing API and cap_id and subcap_id will be u32 with the cpu byte order. The byte order conversions are handled internally by tpm1_getcap_cmd. $ make C=2 M=drivers/char/tpm CHECK drivers/char/tpm/tpm-interface.c drivers/char/tpm/tpm.h:285:24: error: bad constant expression drivers/char/tpm/tpm.h:286:24: error: bad constant expression drivers/char/tpm/tpm.h:287:27: error: bad constant expression drivers/char/tpm/tpm.h:288:27: error: bad constant expression drivers/char/tpm/tpm.h:292:28: error: bad constant expression drivers/char/tpm/tpm.h:293:37: error: bad constant expression drivers/char/tpm/tpm.h:294:29: error: bad constant expression drivers/char/tpm/tpm.h:295:28: error: bad constant expression drivers/char/tpm/tpm.h:296:30: error: bad constant expression drivers/char/tpm/tpm.h:297:36: error: bad constant expression drivers/char/tpm/tpm.h:298:37: error: bad constant expression drivers/char/tpm/tpm-interface.c:444:23: error: incompatible types for operation (==) drivers/char/tpm/tpm-interface.c:444:23: left side has type unsigned int [unsigned] [usertype] subcap_id drivers/char/tpm/tpm-interface.c:444:23: right side has type bad type drivers/char/tpm/tpm-interface.c:444:55: error: incompatible types for operation (==) drivers/char/tpm/tpm-interface.c:444:55: left side has type unsigned int [unsigned] [usertype] subcap_id drivers/char/tpm/tpm-interface.c:444:55: right side has type bad type drivers/char/tpm/tpm-interface.c:450:31: error: incompatible types for operation (==) drivers/char/tpm/tpm-interface.c:450:31: left side has type unsigned int [unsigned] [usertype] subcap_id drivers/char/tpm/tpm-interface.c:450:31: right side has type bad type drivers/char/tpm/tpm-interface.c:451:31: error: incompatible types for operation (==) drivers/char/tpm/tpm-interface.c:451:31: left side has type unsigned int [unsigned] [usertype] subcap_id drivers/char/tpm/tpm-interface.c:451:31: right side has type bad type Fixes: 0883743825e3 ("TPM: sysfs functions consolidation") Signed-off-by: Jarkko Sakkinen Reviewed-by: Jason Gunthorpe --- drivers/char/tpm/tpm-interface.c | 58 +++++++++++++++++----------------------- drivers/char/tpm/tpm-sysfs.c | 36 ++++++++++++++----------- drivers/char/tpm/tpm.h | 31 +++++++++++---------- drivers/char/tpm/tpm_tis_core.c | 3 ++- 4 files changed, 62 insertions(+), 66 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 3edf2e8..fd863ff 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -434,34 +434,40 @@ static const struct tpm_input_header tpm_getcap_header = { .ordinal = TPM_ORD_GET_CAP }; -ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap, - const char *desc) +/** + * tpm1_getcap_cmd() - execute a TPM 1.x TPM_GetCapability command + * @chip: TPM chip to use + * @cap_id: capability + * @subcap_id: subcapability + * @desc: same as with tpm_transmit_cmd + * + * Return: same as with tpm_transmit_cmd + */ +ssize_t tpm1_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 subcap_id, + cap_t *cap, const char *desc) { struct tpm_cmd_t tpm_cmd; int rc; tpm_cmd.header.in = tpm_getcap_header; - if (subcap_id == CAP_VERSION_1_1 || subcap_id == CAP_VERSION_1_2) { - tpm_cmd.params.getcap_in.cap = subcap_id; - /*subcap field not necessary */ + if (cap_id == TPM1_CAP_VERSION_1_1 || + cap_id == TPM1_CAP_VERSION_1_2) { + tpm_cmd.params.getcap_in.cap = cpu_to_be32(cap_id); + /* subcap field not necessary */ tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0); tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32)); } else { - if (subcap_id == TPM_CAP_FLAG_PERM || - subcap_id == TPM_CAP_FLAG_VOL) - tpm_cmd.params.getcap_in.cap = TPM_CAP_FLAG; - else - tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; + tpm_cmd.params.getcap_in.cap = cpu_to_be32(cap_id); tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); - tpm_cmd.params.getcap_in.subcap = subcap_id; + tpm_cmd.params.getcap_in.subcap = cpu_to_be32(subcap_id); } rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 0, desc); - if (!rc) + if (!rc && cap) *cap = tpm_cmd.params.getcap_out.cap; return rc; } -EXPORT_SYMBOL_GPL(tpm_getcap); +EXPORT_SYMBOL_GPL(tpm1_getcap_cmd); #define TPM_ORD_STARTUP cpu_to_be32(153) #define TPM_ST_CLEAR cpu_to_be16(1) @@ -506,13 +512,8 @@ int tpm_get_timeouts(struct tpm_chip *chip) return 0; } - tpm_cmd.header.in = tpm_getcap_header; - tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); - tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; - rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 0, - NULL); - + rc = tpm1_getcap_cmd(chip, TPM1_CAP_PROP, TPM1_CAP_PROP_TIS_TIMEOUT, + NULL, NULL); if (rc == TPM_ERR_INVALID_POSTINIT) { /* The TPM is not started, we are the first to talk to it. Execute a startup command. */ @@ -520,12 +521,8 @@ int tpm_get_timeouts(struct tpm_chip *chip) if (tpm_startup(chip, TPM_ST_CLEAR)) return rc; - tpm_cmd.header.in = tpm_getcap_header; - tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); - tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; - rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, - 0, NULL); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_PROP, + TPM1_CAP_PROP_TIS_TIMEOUT, NULL, NULL); } if (rc) { dev_err(&chip->dev, @@ -581,13 +578,8 @@ int tpm_get_timeouts(struct tpm_chip *chip) chip->timeout_d = usecs_to_jiffies(new_timeout[3]); duration: - tpm_cmd.header.in = tpm_getcap_header; - tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); - tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_DURATION; - - rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 0, - "attempting to determine the durations"); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_PROP, TPM1_CAP_PROP_TIS_TIMEOUT, + NULL, "attempting to determine the durations"); if (rc) return rc; diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index e1f7236..b19f0c4 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -94,8 +94,8 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, char *str = buf; struct tpm_chip *chip = to_tpm_chip(dev); - rc = tpm_getcap(chip, TPM_CAP_PROP_PCR, &cap, - "attempting to determine the number of PCRS"); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_PROP, TPM1_CAP_PROP_PCR, &cap, + "attempting to determine the number of PCRS"); if (rc) return 0; @@ -119,8 +119,9 @@ static ssize_t enabled_show(struct device *dev, struct device_attribute *attr, cap_t cap; ssize_t rc; - rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, - "attempting to determine the permanent enabled state"); + rc = tpm1_getcap_cmd(to_tpm_chip(dev), TPM1_CAP_FLAG, + TPM1_CAP_FLAG_PERM, &cap, + "attempting to determine the permanent enabled state"); if (rc) return 0; @@ -135,8 +136,9 @@ static ssize_t active_show(struct device *dev, struct device_attribute *attr, cap_t cap; ssize_t rc; - rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, - "attempting to determine the permanent active state"); + rc = tpm1_getcap_cmd(to_tpm_chip(dev), TPM1_CAP_FLAG, + TPM1_CAP_FLAG_PERM, &cap, + "attempting to determine the permanent active state"); if (rc) return 0; @@ -151,8 +153,9 @@ static ssize_t owned_show(struct device *dev, struct device_attribute *attr, cap_t cap; ssize_t rc; - rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_PROP_OWNER, &cap, - "attempting to determine the owner state"); + rc = tpm1_getcap_cmd(to_tpm_chip(dev), TPM1_CAP_PROP, + TPM1_CAP_PROP_OWNER, &cap, + "attempting to determine the owner state"); if (rc) return 0; @@ -167,8 +170,9 @@ static ssize_t temp_deactivated_show(struct device *dev, cap_t cap; ssize_t rc; - rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_VOL, &cap, - "attempting to determine the temporary state"); + rc = tpm1_getcap_cmd(to_tpm_chip(dev), TPM1_CAP_FLAG, TPM1_CAP_FLAG_VOL, + &cap, + "attempting to determine the temporary state"); if (rc) return 0; @@ -185,16 +189,16 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr, ssize_t rc; char *str = buf; - rc = tpm_getcap(chip, TPM_CAP_PROP_MANUFACTURER, &cap, - "attempting to determine the manufacturer"); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_PROP, TPM1_CAP_PROP_MANUFACTURER, + &cap, "attempting to determine the manufacturer"); if (rc) return 0; str += sprintf(str, "Manufacturer: 0x%x\n", be32_to_cpu(cap.manufacturer_id)); /* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */ - rc = tpm_getcap(chip, CAP_VERSION_1_2, &cap, - "attempting to determine the 1.2 version"); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_VERSION_1_2, 0, &cap, + "attempting to determine the 1.2 version"); if (!rc) { str += sprintf(str, "TCG version: %d.%d\nFirmware version: %d.%d\n", @@ -204,8 +208,8 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr, cap.tpm_version_1_2.revMinor); } else { /* Otherwise just use TPM_STRUCT_VER */ - rc = tpm_getcap(chip, CAP_VERSION_1_1, &cap, - "attempting to determine the 1.1 version"); + rc = tpm1_getcap_cmd(chip, TPM1_CAP_VERSION_1_1, 0, &cap, + "attempting to determine the 1.1 version"); if (rc) return 0; str += sprintf(str, diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 1d1361a..3e952fb 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -281,22 +281,21 @@ typedef union { struct duration_t duration; } cap_t; -enum tpm_capabilities { - TPM_CAP_FLAG = cpu_to_be32(4), - TPM_CAP_PROP = cpu_to_be32(5), - CAP_VERSION_1_1 = cpu_to_be32(0x06), - CAP_VERSION_1_2 = cpu_to_be32(0x1A) +enum tpm1_capabilities { + TPM1_CAP_FLAG = 0x04, + TPM1_CAP_PROP = 0x05, + TPM1_CAP_VERSION_1_1 = 0x06, + TPM1_CAP_VERSION_1_2 = 0x1A, }; -enum tpm_sub_capabilities { - TPM_CAP_PROP_PCR = cpu_to_be32(0x101), - TPM_CAP_PROP_MANUFACTURER = cpu_to_be32(0x103), - TPM_CAP_FLAG_PERM = cpu_to_be32(0x108), - TPM_CAP_FLAG_VOL = cpu_to_be32(0x109), - TPM_CAP_PROP_OWNER = cpu_to_be32(0x111), - TPM_CAP_PROP_TIS_TIMEOUT = cpu_to_be32(0x115), - TPM_CAP_PROP_TIS_DURATION = cpu_to_be32(0x120), - +enum tpm1_sub_capabilities { + TPM1_CAP_PROP_PCR = 0x101, + TPM1_CAP_PROP_MANUFACTURER = 0x103, + TPM1_CAP_FLAG_PERM = 0x108, + TPM1_CAP_FLAG_VOL = 0x109, + TPM1_CAP_PROP_OWNER = 0x111, + TPM1_CAP_PROP_TIS_TIMEOUT = 0x115, + TPM1_CAP_PROP_TIS_DURATION = 0x120, }; struct tpm_getcap_params_in { @@ -484,8 +483,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, unsigned int flags); ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *cmd, int len, unsigned int flags, const char *desc); -ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap, - const char *desc); +ssize_t tpm1_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 subcap_id, + cap_t *cap, const char *desc); int tpm_get_timeouts(struct tpm_chip *chip); int tpm1_auto_startup(struct tpm_chip *chip); int tpm_do_selftest(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index f22caf8..88c8d8a 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -535,7 +535,8 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) if (chip->flags & TPM_CHIP_FLAG_TPM2) return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else - return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc); + return tpm1_getcap_cmd(chip, TPM1_CAP_PROP, + TPM1_CAP_PROP_TIS_TIMEOUT, &cap, desc); } /* Register the IRQ and issue a command that will cause an interrupt. If an