Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1794468rdb; Wed, 31 Jan 2024 09:12:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9Lt4FaRMb4FGNZO0NiAcLpvUyRoN5ucWe0nJQ2q0/97YrcYFoWQ3FwG3p3StrsvtNhr9H X-Received: by 2002:a05:6402:35c1:b0:55f:957b:318c with SMTP id z1-20020a05640235c100b0055f957b318cmr1682950edc.8.1706721125712; Wed, 31 Jan 2024 09:12:05 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1706721125; cv=pass; d=google.com; s=arc-20160816; b=fjF5EUb2Q4XD5RfOPqOfM4FVNIfcodwkEO5SOej2GPh7oTWzQ7BPNI8QQteOC0C9ty 5/aPNG721nP2spVE+wDd5GVN8T+JL31f3kKDyRWBkNHQg/lZF2zRPZY7Vb0jM5Yj9c0k ZxlKjX+C2RklTlip+bdRJ4aIaCxmnOOOjxh8LUyMb0WSbdoQozOjEsjUxjy5/Nl/arWl IMQsefow8l1uSJzVM3vKdxdPL27KwUyylqSc5oqhZsapCjqlhequC0Nueit/ytSJZ+qo hjsUvWkVDrRJgfcNkB0SiSE5eXn/jrc/eCpMeI0wNry4nz6qWtCe1X+L3wzOv7tmrjSY ISVA== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:delivered-to; bh=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; fh=FnjGj4EmBNFCWTqVoIf+bTN7bRySKXRfnSXC48NjZAM=; b=WSv64UWvQyxPaO4OtCObzpSd9vYsTH7GqtpgxIT0ZD1ejIEMmT/fwO2Ydh3LK22xYx TrF4Qs6Wqyd3UAhE7RtYTaGtLxQdhpmy7j9wgCVjh+uLZUiC4CEpd4EBLX7UcEE+leLu Xs7ugxfC2kgyAGaL+hqJbJdc0yrp/VJU2lIGkaGrr4DyZm9jKtiJcpRoEu/DIJiczM5M NcgrsweF3z8mbAApIpER/yfOl6mGmzA2zGmVhmsBTbvrqOj8R3iAivoMg0st4DWc344k 7Mlgs2iF0FiJnRGPsCEZi2/92rW/eh6yeZc8k4GStF5M9scwqpYDkWUgrEbCtW4+uciJ B7Ug==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b="eISNC/Lz"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46877-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCV6KWvjy+Ht5fQBNO3KFcasL3NxPpobfW+6Klu89+qKO0ldbFt/XwM7E3oUUQ6y0qh77qkvPX4HocS0EVQr6KCWkYSPxQ1yATHs2GkW/Q== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p10-20020a056402044a00b00557a9f389aasi5835602edw.559.2024.01.31.09.12.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:12:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b="eISNC/Lz"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46877-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1C35D1F269A2 for ; Wed, 31 Jan 2024 17:11:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C63591339B6; Wed, 31 Jan 2024 17:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b="eISNC/Lz" Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B91112CDAB; Wed, 31 Jan 2024 17:09:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.50 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720949; cv=pass; b=T0O8fjpK/9w6CYh2+leekEdr+lFNg0HI3jjgPw0wgCCTAUaIZN9/emNqKd31fiMEzwPj6DUsrK6nojWtSwRRSCQhhUL9b3Z3nGmsz/AeXZ5LbJllmDZGRasg1maWKKrHFwW6GvFEsEvjU4h6NWcEp71vcrXSOcQ9HU8J0/RwY7o= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720949; c=relaxed/simple; bh=trM7msgFSArPjPrDsbJnOiFND6qGuUZ3YFCmeWhK78U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xw1XzEUtJqlWGefjRadPw8SQTFihQY1IMzpP7+RUhHLPs15uyVzffBqb1adwaYQW5vxaVGqgar2WnHn1RMsomeZWIq5wdV8k2L/OIvU8Zb8HqIshtXtraIDEYD/3VsuKADsdq8qIbcMKV5wgI9Cckz6V054LH7JeKRCDnP/XSHc= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com; spf=pass smtp.mailfrom=apertussolutions.com; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b=eISNC/Lz; arc=pass smtp.client-ip=136.143.188.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=apertussolutions.com Delivered-To: dpsmith@apertussolutions.com ARC-Seal: i=1; a=rsa-sha256; t=1706720920; cv=none; d=zohomail.com; s=zohoarc; b=PNN1/Biy48y5Kta70ks1MYvS51v2IjkqawXWdzI++/D9OtAgn/Ni3UrU4XXUpSYL5EgaDpwGI+G6ASISPtunVQXy2RE8z2jYD44qoPU10QsL8GmVsyiqvtvY94Js8qXOgcRr9MZ2fPwNxC7uTHjgwi0eW9fQ31ci2vK+JWkPrJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706720920; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; b=m8r5EFVqBaR9jLnuARSgDyHu3exFMmVu40uPCctDAO5NgzFJUqPLOMN6Mr+52hjIJP/3a5lA79N88l8Enkop9RV+SIvXWJP5CH8OEbqoGhvHMYxevHwpfICzOYbNj3Eoa0YFNHppQR/AwBeEddxZeY6vFX2f42ksmvYf7c3hzwE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706720920; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; b=eISNC/LzWk1CAU88clvqoeCIBlQfQmDJpqjp39np/pyvPIV10RakmWMjssapiZhe mN0j9grEHlVjZo9s+1LsyemfPet8SnkP+pjVlww43PxseUbqbFnFjpb6cTA5BeWeTVt km6K82n3tniVMj1cMWadWx7JZ1dy8tjsmIjbughk= Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1706720919703416.7846206921556; Wed, 31 Jan 2024 09:08:39 -0800 (PST) From: "Daniel P. Smith" To: Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Daniel P. Smith" , Ross Philipson , Peter Huewe , Jarkko Sakkinen Subject: [PATCH 3/3] tpm: make locality request return value consistent Date: Wed, 31 Jan 2024 12:08:23 -0500 Message-Id: <20240131170824.6183-4-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240131170824.6183-1-dpsmith@apertussolutions.com> References: <20240131170824.6183-1-dpsmith@apertussolutions.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External The function tpm_tis_request_locality() is expected to return the locality value that was requested, or a negative error code upon failure. If it is called while locality_count of struct tis_data is non-zero, no actual locality request will be sent. Because the ret variable is initially set to 0, the locality_count will still get increased, and the function will return 0. For a caller, this would indicate that locality 0 was successfully requested and not the state changes just mentioned. Additionally, the function __tpm_tis_request_locality() provides inconsistent error codes. It will provide either a failed IO write or a -1 should it have timed out waiting for locality request to succeed. This commit changes __tpm_tis_request_locality() to return valid negative error codes to reflect the reason it fails. It then adjusts the return value check in tpm_tis_request_locality() to check for a non-negative return value before incrementing locality_cout. In addition, the initial value of the ret value is set to a negative error to ensure the check does not pass if __tpm_tis_request_locality() is not called. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm_tis_core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 5709f87991d9..352fefc07823 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -208,7 +208,7 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) again: timeout = stop - jiffies; if ((long)timeout <= 0) - return -1; + return -EBUSY; rc = wait_event_interruptible_timeout(priv->int_queue, (check_locality (chip, l)), @@ -227,18 +227,21 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) tpm_msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); } - return -1; + return -EBUSY; } static int tpm_tis_request_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int ret = 0; + int ret = -EBUSY; + + if (l < 0 || l > TPM_MAX_LOCALITY) + return -EINVAL; mutex_lock(&priv->locality_count_mutex); if (priv->locality_count == 0) ret = __tpm_tis_request_locality(chip, l); - if (!ret) + if (ret >= 0) priv->locality_count++; mutex_unlock(&priv->locality_count_mutex); return ret; -- 2.30.2