From patchwork Sat Mar 18 08:59:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry Snitselaar X-Patchwork-Id: 740589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3vlblX4T8yz9s73 for ; Sat, 18 Mar 2017 20:00:40 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cpADw-0007Lk-Rk; Sat, 18 Mar 2017 09:00:32 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cpADv-0007Lf-HR for tpmdd-devel@lists.sourceforge.net; Sat, 18 Mar 2017 09:00:31 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=jsnitsel@redhat.com; helo=mx1.redhat.com; Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cpADt-0004Nx-9a for tpmdd-devel@lists.sourceforge.net; Sat, 18 Mar 2017 09:00:31 +0000 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 mx1.redhat.com (Postfix) with ESMTPS id 6EE118F27A; Sat, 18 Mar 2017 09:00:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6EE118F27A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jsnitsel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6EE118F27A Received: from localhost.localdomain.com (ovpn-116-30.phx2.redhat.com [10.3.116.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9E7E5DD62; Sat, 18 Mar 2017 09:00:23 +0000 (UTC) From: Jerry Snitselaar To: tpmdd-devel@lists.sourceforge.net Date: Sat, 18 Mar 2017 01:59:57 -0700 Message-Id: <20170318085957.12277-1-jsnitsel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 18 Mar 2017 09:00:24 +0000 (UTC) X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1cpADt-0004Nx-9a Cc: Christophe Ricard , linux-kernel@vger.kernel.org Subject: [tpmdd-devel] [PATCH] tpm: make check_locality return bool 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 Since check_locality is checking to see if a certain locality is active, return true if active otherwise return false. Cc: Christophe Ricard Cc: Jason Gunthorpe Cc: Marcel Selhorst Cc: Jarkko Sakkinen Cc: Peter Huewe Signed-off-by: Jerry Snitselaar Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- Tested tpm_tis, but don't have the ability to test Infineon or STMicro drivers. drivers/char/tpm/st33zp24/st33zp24.c | 12 ++++++------ drivers/char/tpm/tpm_i2c_infineon.c | 12 ++++++------ drivers/char/tpm/tpm_tis_core.c | 20 +++++++++++--------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c index e8e0f7c02686..4d1dc8b46877 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -117,9 +117,9 @@ static u8 st33zp24_status(struct tpm_chip *chip) /* * check_locality if the locality is active * @param: chip, the tpm chip description - * @return: the active locality or -EACCESS. + * @return: true if LOCALITY0 is active, otherwise false */ -static int check_locality(struct tpm_chip *chip) +static bool check_locality(struct tpm_chip *chip) { struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev); u8 data; @@ -129,9 +129,9 @@ static int check_locality(struct tpm_chip *chip) if (status && (data & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) - return tpm_dev->locality; + return true; - return -EACCES; + return false; } /* check_locality() */ /* @@ -146,7 +146,7 @@ static int request_locality(struct tpm_chip *chip) long ret; u8 data; - if (check_locality(chip) == tpm_dev->locality) + if (check_locality(chip)) return tpm_dev->locality; data = TPM_ACCESS_REQUEST_USE; @@ -158,7 +158,7 @@ static int request_locality(struct tpm_chip *chip) /* Request locality is usually effective after the request */ do { - if (check_locality(chip) >= 0) + if (check_locality(chip)) return tpm_dev->locality; msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c index 62ee44e57ddc..dc47fa222a26 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -278,22 +278,22 @@ enum tis_defaults { #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4)) #define TPM_DID_VID(l) (0x0006 | ((l) << 4)) -static int check_locality(struct tpm_chip *chip, int loc) +static bool check_locality(struct tpm_chip *chip, int loc) { u8 buf; int rc; rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1); if (rc < 0) - return rc; + return false; if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) { tpm_dev.locality = loc; - return loc; + return true; } - return -EIO; + return false; } /* implementation similar to tpm_tis */ @@ -315,7 +315,7 @@ static int request_locality(struct tpm_chip *chip, int loc) unsigned long stop; u8 buf = TPM_ACCESS_REQUEST_USE; - if (check_locality(chip, loc) >= 0) + if (check_locality(chip, loc)) return loc; iic_tpm_write(TPM_ACCESS(loc), &buf, 1); @@ -323,7 +323,7 @@ static int request_locality(struct tpm_chip *chip, int loc) /* wait for burstcount */ stop = jiffies + chip->timeout_a; do { - if (check_locality(chip, loc) >= 0) + if (check_locality(chip, loc)) return loc; usleep_range(TPM_TIMEOUT_US_LOW, TPM_TIMEOUT_US_HI); } while (time_before(jiffies, stop)); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c0f296b5d413..93d641996249 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -56,7 +56,7 @@ static int wait_startup(struct tpm_chip *chip, int l) return -1; } -static int check_locality(struct tpm_chip *chip, int l) +static bool check_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc; @@ -64,13 +64,15 @@ static int check_locality(struct tpm_chip *chip, int l) rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); if (rc < 0) - return rc; + return false; if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == - (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) - return priv->locality = l; + (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) { + priv->locality = l; + return true; + } - return -1; + return false; } static void release_locality(struct tpm_chip *chip, int l, int force) @@ -96,7 +98,7 @@ static int request_locality(struct tpm_chip *chip, int l) unsigned long stop, timeout; long rc; - if (check_locality(chip, l) >= 0) + if (check_locality(chip, l)) return l; rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE); @@ -112,7 +114,7 @@ static int request_locality(struct tpm_chip *chip, int l) return -1; rc = wait_event_interruptible_timeout(priv->int_queue, (check_locality - (chip, l) >= 0), + (chip, l)), timeout); if (rc > 0) return l; @@ -123,7 +125,7 @@ static int request_locality(struct tpm_chip *chip, int l) } else { /* wait for burstcount */ do { - if (check_locality(chip, l) >= 0) + if (check_locality(chip, l)) return l; msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); @@ -533,7 +535,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) for (i = 0; i < 5; i++) - if (check_locality(chip, i) >= 0) + if (check_locality(chip, i)) break; if (interrupt & (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |