diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-10-02 13:12:11 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-10-02 15:02:26 +0200 |
commit | 5a71b83002800c6f6a1c3566f78957cd2bb330bf (patch) | |
tree | 6e22a8a3d331f40d3122bd8edb7a686d98eb4432 /src/boot | |
parent | memory-util: move memzero() to src/fundamental/ to share with UEFI (diff) | |
download | systemd-5a71b83002800c6f6a1c3566f78957cd2bb330bf.tar.xz systemd-5a71b83002800c6f6a1c3566f78957cd2bb330bf.zip |
util: add xmalloc0() helper
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/measure.c | 6 | ||||
-rw-r--r-- | src/boot/efi/util.h | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c index 6f7282dc7d..f9aabb42be 100644 --- a/src/boot/efi/measure.c +++ b/src/boot/efi/measure.c @@ -25,8 +25,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log( assert(description); desc_len = strsize16(description); - tcg_event = xmalloc(offsetof(TCG_PCR_EVENT, Event) + desc_len); - memzero(tcg_event, offsetof(TCG_PCR_EVENT, Event) + desc_len); + tcg_event = xmalloc0(offsetof(TCG_PCR_EVENT, Event) + desc_len); *tcg_event = (TCG_PCR_EVENT) { .EventSize = desc_len, .PCRIndex = pcrindex, @@ -63,8 +62,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log( * here. */ desc_len = strsize16(description); - tcg_event = xmalloc(offsetof(EFI_TCG2_EVENT, Event) + desc_len); - memzero(tcg_event, offsetof(EFI_TCG2_EVENT, Event) + desc_len); + tcg_event = xmalloc0(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), diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index de0c83ddb9..10620dabca 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -35,6 +35,12 @@ 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)); |