From patchwork Tue Feb 9 01:44:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1438079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZQjt2fYCz9sSC for ; Tue, 9 Feb 2021 12:46:58 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DZQjs38D1zDvYg for ; Tue, 9 Feb 2021 12:46:57 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 4DZQhm62YQzDvZS for ; Tue, 9 Feb 2021 12:46:00 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 36F73AE8027B; Mon, 8 Feb 2021 20:45:27 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 9 Feb 2021 12:44:55 +1100 Message-Id: <20210209014457.108301-11-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210209014457.108301-1-aik@ozlabs.ru> References: <20210209014457.108301-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v2 10/12] libtpm: Compile with -Wextra X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" -Wextra enables a bunch of rather useful checks which this fixes. Note this adds MIN() in tpm_gpt_set_lba1() so it may potentially fail which is unlikely as the length comes from disk-label's block-size which is used in other places. Signed-off-by: Alexey Kardashevskiy --- lib/libtpm/tcgbios.c | 10 +++++----- lib/libtpm/tpm_drivers.c | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index 8e808115bc59..f9e46027b599 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -356,7 +356,7 @@ tpm_simple_cmd(uint8_t locty, uint32_t ordinal, int param_size, uint16_t param, memset(obuffer, 0, sizeof(obuffer)); ret = spapr_transmit(locty, &req.trqh, obuffer, &obuffer_len, to_t); - ret = ret ? -1 : be32_to_cpu(trsh->errcode); + ret = ret ? -1 : (int) be32_to_cpu(trsh->errcode); dprintf("Return from tpm_simple_cmd(%x, %x) = %x\n", ordinal, param, ret); @@ -382,7 +382,7 @@ tpm20_getcapability(uint32_t capability, uint32_t property, uint32_t count, TPM_DURATION_TYPE_SHORT); ret = (ret || rsize < be32_to_cpu(rsp->totlen)) ? -1 - : be32_to_cpu(rsp->errcode); + : (int) be32_to_cpu(rsp->errcode); dprintf("TCGBIOS: Return value from sending TPM2_CC_GetCapability = 0x%08x\n", ret); @@ -664,7 +664,7 @@ static int tpm20_write_EfiSpecIdEventStruct(void) }; struct tpms_pcr_selection *sel; void *nsel, *end; - int event_size; + unsigned event_size; uint8_t *vendorInfoSize; struct tpm_log_entry le = { .hdr.eventtype = cpu_to_log32(EV_NO_ACTION), @@ -1024,7 +1024,7 @@ void tpm_gpt_set_lba1(const uint8_t *addr, uint32_t length) return; memcpy(&uefi_gpt_data->EfiPartitionHeader, - addr, sizeof(uefi_gpt_data->EfiPartitionHeader)); + addr, MIN(sizeof(uefi_gpt_data->EfiPartitionHeader), length)); uefi_gpt_data->NumberOfPartitions = 0; } @@ -1252,7 +1252,7 @@ tpm20_set_pcrbanks(uint32_t active_banks) ret = spapr_transmit(0, &trpa.hdr, &rsp, &resp_length, TPM_DURATION_TYPE_SHORT); - ret = ret ? -1 : be32_to_cpu(rsp.errcode); + ret = ret ? -1 : (int) be32_to_cpu(rsp.errcode); return ret; } diff --git a/lib/libtpm/tpm_drivers.c b/lib/libtpm/tpm_drivers.c index 0e13561d0fa0..85cb3098712d 100644 --- a/lib/libtpm/tpm_drivers.c +++ b/lib/libtpm/tpm_drivers.c @@ -357,8 +357,7 @@ static bool spapr_vtpm_senddata(const uint8_t *const data, uint32_t len) static bool spapr_vtpm_waitresponseready(enum tpm_duration_type to_t) { - uint32_t timeout = tpm2_durations[to_t]; - int i; + uint32_t i, timeout = tpm2_durations[to_t]; if (vtpm_drv_error_get() != VTPM_DRV_ERROR_NO_FAILURE) { printf("%s: VTPM CRQ: In failure mode\n", __func__); @@ -426,6 +425,8 @@ int spapr_transmit(uint8_t locty, struct tpm_req_header *req, void *respbuffer, uint32_t *respbufferlen, enum tpm_duration_type to_t) { + if (locty) + return -1; if (!spapr_vtpm_senddata((uint8_t *)req, be32_to_cpu(req->totlen)) || !spapr_vtpm_waitresponseready(to_t) || !spapr_vtpm_readresponse(respbuffer, respbufferlen) ||