diff mbox series

[2/2] lib/libtpm: Silence compiler warning about unaligned pointer value

Message ID 20230918122659.92014-3-thuth@redhat.com
State Superseded
Headers show
Series Silence compiler warnings in tpm code | expand

Commit Message

Thomas Huth Sept. 18, 2023, 12:26 p.m. UTC
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@redhat.com>
---
 lib/libtpm/tpm_drivers.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

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