From nobody Thu Dec 18 08:37:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BC45E342519; Tue, 16 Dec 2025 09:22:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765876958; cv=none; b=k9TfMkIJbwpMdt2LGhlTvYRnGZsr7DUJtN9OCOfRLixrqAhkHB7hhfk2bC9yNJsy3iNOZkEPXYaoYvXUh29NGJYQEUzc8Vj1PK6dlm2hsGCkMKQw6kmXEmETypTQF4oNEgbXaczbFL2mv5/3dhK9wn+8n4Y/6MYegE6Fv5nfsug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765876958; c=relaxed/simple; bh=UwhXqY11HYtozC373wWwhiWWZ8a9IT8dHvu1WoeGMXs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Vj49UYBwgJdaCplfwc8dcJAd5g83xF7mSZZNtQ/K442OvnWxrcqkexaNC66ABhPWUHiIrQaTi29oYnRrJpQYHvb91qZzpYn8Q8/fWLMp3Eu+/stn2Rjx/wDF63nQRWKoLS2buD8YCOLSfVAtC2N6t8uU2arsOxR7E96mMbARslc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RpVdCINn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RpVdCINn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E816FC19422; Tue, 16 Dec 2025 09:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765876958; bh=UwhXqY11HYtozC373wWwhiWWZ8a9IT8dHvu1WoeGMXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RpVdCINn1JRuo6VG/aJD++e7/pGVfUz7vz0AZposHXTPvvx8nFs1cs2/qiKQrmbEz GELhV7gXrc7ad29VZQa3jMr94QGwPSQei7lkg26Ka8+y+CiCZ0nNyU4G+rSsjQIDUy ylshZawf1AWdfzxZ0d6w8alJ9DGyTD9tuLTp26jGQDkVIcsm6NIWoCQowcCqgaNpeS b1nHfgIITHkWruftQRzYBdIMgYr2RsXSfOSRHvfpLx61kslyZ6+l0I65urZu75vXne yvsqoqqNnRQ8QDfFIP5YBfSP+nnEe+kapkcVulqGc8Q/3r2CvQrntmkNnls82fUK0o l599j4GsVHZuA== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , linux-kernel@vger.kernel.org (open list), keyrings@vger.kernel.org (open list:KEYS/KEYRINGS), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH v8 10/12] tpm-buf: Remove tpm_buf_append_handle Date: Tue, 16 Dec 2025 11:21:44 +0200 Message-Id: <20251216092147.2326606-11-jarkko@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251216092147.2326606-1-jarkko@kernel.org> References: <20251216092147.2326606-1-jarkko@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since the number of handles is fixed to a single handle, eliminate all uses of buf->handles and deduce values during compile-time. Signed-off-by: Jarkko Sakkinen --- v2: - Streamline the code change and remove dead code. --- drivers/char/tpm/tpm-buf.c | 23 ----------------------- drivers/char/tpm/tpm2-cmd.c | 2 +- drivers/char/tpm/tpm2-sessions.c | 14 ++------------ include/linux/tpm.h | 2 -- 4 files changed, 3 insertions(+), 38 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index dc882fc9fa9e..1d2b87455d3a 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -44,7 +44,6 @@ void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordi= nal) head->tag =3D cpu_to_be16(tag); head->length =3D cpu_to_be32(sizeof(*head)); head->ordinal =3D cpu_to_be32(ordinal); - buf->handles =3D 0; } EXPORT_SYMBOL_GPL(tpm_buf_reset); =20 @@ -146,26 +145,6 @@ void tpm_buf_append_u32(struct tpm_buf *buf, const u32= value) } EXPORT_SYMBOL_GPL(tpm_buf_append_u32); =20 -/** - * tpm_buf_append_handle() - Add a handle - * @chip: &tpm_chip instance - * @buf: &tpm_buf instance - * @handle: a TPM object handle - * - * Add a handle to the buffer, and increase the count tracking the number = of - * handles in the command buffer. Works only for command buffers. - */ -void tpm_buf_append_handle(struct tpm_chip *chip, struct tpm_buf *buf, u32= handle) -{ - if (buf->flags & TPM_BUF_TPM2B) { - dev_err(&chip->dev, "Invalid buffer type (TPM2B)\n"); - return; - } - - tpm_buf_append_u32(buf, handle); - buf->handles++; -} - /** * tpm_buf_read() - Read from a TPM buffer * @buf: &tpm_buf instance @@ -242,5 +221,3 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset) return be32_to_cpu(value); } EXPORT_SYMBOL_GPL(tpm_buf_read_u32); - - diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 461e85c3abe5..8ba6cd6819f1 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -210,7 +210,7 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, } tpm_buf_append_hmac_session(chip, &buf, 0, NULL, 0); } else { - tpm_buf_append_handle(chip, &buf, pcr_idx); + tpm_buf_append_u32(&buf, pcr_idx); tpm_buf_append_auth(chip, &buf, NULL, 0); } =20 diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessi= ons.c index 98cea20040cf..016bed63a755 100644 --- a/drivers/char/tpm/tpm2-sessions.c +++ b/drivers/char/tpm/tpm2-sessions.c @@ -268,7 +268,7 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct t= pm_buf *buf, } =20 if (!tpm2_chip_auth(chip)) { - tpm_buf_append_handle(chip, buf, handle); + tpm_buf_append_u32(buf, handle); return 0; } =20 @@ -295,17 +295,7 @@ EXPORT_SYMBOL_GPL(tpm_buf_append_name); void tpm_buf_append_auth(struct tpm_chip *chip, struct tpm_buf *buf, u8 *passphrase, int passphrase_len) { - /* offset tells us where the sessions area begins */ - int offset =3D buf->handles * 4 + TPM_HEADER_SIZE; - u32 len =3D 9 + passphrase_len; - - if (tpm_buf_length(buf) !=3D offset) { - /* not the first session so update the existing length */ - len +=3D get_unaligned_be32(&buf->data[offset]); - put_unaligned_be32(len, &buf->data[offset]); - } else { - tpm_buf_append_u32(buf, len); - } + tpm_buf_append_u32(buf, 9 + passphrase_len); /* auth handle */ tpm_buf_append_u32(buf, TPM2_RS_PW); /* nonce */ diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 72610f1aa402..4a6ba16a962c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -397,7 +397,6 @@ struct tpm_buf { u32 flags; u32 length; u8 *data; - u8 handles; }; =20 enum tpm2_object_attributes { @@ -441,7 +440,6 @@ void tpm_buf_append_u32(struct tpm_buf *buf, const u32 = value); u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset); u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); -void tpm_buf_append_handle(struct tpm_chip *chip, struct tpm_buf *buf, u32= handle); =20 /* * Check if TPM device is in the firmware upgrade mode. --=20 2.39.5