52 lines
1.5 KiB
Diff
52 lines
1.5 KiB
Diff
|
From 84aed24cce13f1432d050b72a7717df1098c9381 Mon Sep 17 00:00:00 2001
|
||
|
From: Lennart Poettering <lennart@poettering.net>
|
||
|
Date: Fri, 24 Feb 2023 18:20:50 +0100
|
||
|
Subject: [PATCH] tpm2-util: use compound initialization when allocating tpm2
|
||
|
objects
|
||
|
|
||
|
(cherry picked from commit d70e4bc9f1395a5ca48ac4f6b3e71e64029312e1)
|
||
|
|
||
|
Related: RHEL-16182
|
||
|
---
|
||
|
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 bc3ae8340d..bf36b4de95 100644
|
||
|
--- a/src/shared/tpm2-util.c
|
||
|
+++ b/src/shared/tpm2-util.c
|
||
|
@@ -329,11 +329,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)
|
||
|
@@ -481,12 +483,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);
|
||
|
|