[SLOF] [PATCH 2/2] lib/libtpm: Silence compiler warning about unaligned pointer value
Thomas Huth
thuth at redhat.com
Mon Sep 18 22:26:59 AEST 2023
GCC v13.2.1 complains:
tpm_drivers.c: In function ‘spapr_send_crq_and_wait’:
tpm_drivers.c:153:9: warning: converting a packed ‘struct crq’
pointer (alignment 1) to a ‘uint64_t’ {aka ‘long long unsigned
int’} pointer (alignment 8) may result in an unaligned pointer
value [-Waddress-of-packed-member]
153 | rc = hv_send_crq(unit, (uint64_t *)crq);
| ^~
tpm_drivers.c:34:8: note: defined here
34 | struct crq {
| ^~~
Since all members of this struct are naturally aligned, it's
indeed better to avoid the "packed" attribute here and use
a _Static_assert() to make sure that no padding is added here
by accident.
Signed-off-by: Thomas Huth <thuth at redhat.com>
---
lib/libtpm/tpm_drivers.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/libtpm/tpm_drivers.c b/lib/libtpm/tpm_drivers.c
index 85cb309..ac28072 100644
--- a/lib/libtpm/tpm_drivers.c
+++ b/lib/libtpm/tpm_drivers.c
@@ -37,7 +37,8 @@ struct crq {
uint16_t len;
uint32_t data;
uint64_t reserved;
-} __attribute__((packed));
+};
+_Static_assert(sizeof(struct crq) == 16, "padding in struct crq");
#define PAPR_VTPM_INIT_CRQ_COMMAND 0xC0
#define PAPR_VTPM_VALID_COMMAND 0x80
--
2.41.0
More information about the SLOF
mailing list