From d70e4bc9f1395a5ca48ac4f6b3e71e64029312e1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Feb 2023 18:20:50 +0100 Subject: [PATCH] tpm2-util: use compound initialization when allocating tpm2 objects --- src/shared/tpm2-util.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 6027a680fab..de706a10db6 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -126,11 +126,13 @@ int tpm2_context_new(const char *device, Tpm2Context **ret_context) { assert(ret_context); - context = new0(Tpm2Context, 1); + context = new(Tpm2Context, 1); if (!context) return log_oom(); - context->n_ref = 1; + *context = (Tpm2Context) { + .n_ref = 1, + }; r = dlopen_tpm2(); if (r < 0) @@ -258,12 +260,14 @@ int tpm2_handle_new(Tpm2Context *context, Tpm2Handle **ret_handle) { assert(ret_handle); - handle = new0(Tpm2Handle, 1); + handle = new(Tpm2Handle, 1); if (!handle) return log_oom(); - handle->tpm2_context = tpm2_context_ref(context); - handle->esys_handle = ESYS_TR_NONE; + *handle = (Tpm2Handle) { + .tpm2_context = tpm2_context_ref(context), + .esys_handle = ESYS_TR_NONE, + }; *ret_handle = TAKE_PTR(handle);