From 586f19976af82e7bbb4f776ad841b190f700d3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 17 Oct 2023 10:55:57 +0200 Subject: [PATCH 1/2] efi: do not memzero fields before initializing them In all three cases we immediately overwrite the whole field anyway, so the call to memzero is not needed. --- src/boot/efi/measure.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c index 28ec6b7d82..01c97c883c 100644 --- a/src/boot/efi/measure.c +++ b/src/boot/efi/measure.c @@ -25,7 +25,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log( assert(description); desc_len = strsize16(description); - tcg_event = xmalloc0(offsetof(TCG_PCR_EVENT, Event) + desc_len); + tcg_event = xmalloc(offsetof(TCG_PCR_EVENT, Event) + desc_len); *tcg_event = (TCG_PCR_EVENT) { .EventSize = desc_len, .PCRIndex = pcrindex, @@ -62,8 +62,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_tagged_event_log( desc_len = strsize16(description); event_size = offsetof(EFI_TCG2_EVENT, Event) + offsetof(EFI_TCG2_TAGGED_EVENT, Event) + desc_len; - event = xmalloc0(event_size); - + event = xmalloc(event_size); *event = (struct event) { .tcg_event = (EFI_TCG2_EVENT) { .Size = event_size, @@ -106,7 +105,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log( * here. */ desc_len = strsize16(description); - tcg_event = xmalloc0(offsetof(EFI_TCG2_EVENT, Event) + desc_len); + tcg_event = xmalloc(offsetof(EFI_TCG2_EVENT, Event) + desc_len); *tcg_event = (EFI_TCG2_EVENT) { .Size = offsetof(EFI_TCG2_EVENT, Event) + desc_len, .Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER), From 6e98ddf825ce04c8d5514c0a1085c4649ee3aca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 17 Oct 2023 10:56:45 +0200 Subject: [PATCH 2/2] efi: drop unused xmalloc0() Keeping this separate to make it easy to revert if it's ever needed again. --- src/boot/efi/util.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 17215bb81a..aef831d132 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -35,12 +35,6 @@ static inline void *xmalloc(size_t size) { return p; } -#define xmalloc0(size) \ - ({ \ - size_t _size_ = (size); \ - memzero(xmalloc(_size_), _size_); \ - }) - _malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_ static inline void *xmalloc_multiply(size_t size, size_t n) { assert_se(!__builtin_mul_overflow(size, n, &size));