Re: drivers/acpi/prmt.c:156:29: error: passing 1-byte aligned argument to 4-byte aligned parameter 1 of 'efi_pa_va_lookup' may result in an unaligned pointer access [-Werror,-Walign-mismatch]
From: Ard Biesheuvel
Date: Wed Oct 23 2024 - 15:37:56 EST
On Wed, 23 Oct 2024 at 21:06, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
>
> > Config: https://storage.tuxsuite.com/public/linaro/lkft/builds/2npIm4ZOkWenPJ71UOZG57R0jXE/config
>
> > drivers/acpi/prmt.c:156:29: error: passing 1-byte aligned argument to
> > 4-byte aligned parameter 1 of 'efi_pa_va_lookup' may result in an
> > unaligned pointer access [-Werror,-Walign-mismatch]
> > 156 | (void *)efi_pa_va_lookup(&th->guid,
> > handler_info->handler_address);
> > | ^
>
> The problem is that efi_guid_t is alighned but guid_t is not. I would have
> thought that Clang would say that even though the alignment in for &th->guid
> isn't spelled out explicitly, it would still end up being aligned at 8 bytes.
>
Yeah this is bizarre tbh. The alignment of the type should be irrelevant here.
> typedef guid_t efi_guid_t __aligned(__alignof__(u32));
>
> The relevant code looks like this:
>
> include/linux/uuid.h
> 13 #define UUID_SIZE 16
> 14
> 15 typedef struct {
> 16 __u8 b[UUID_SIZE];
> 17 } guid_t;
>
> drivers/acpi/prmt.c
> 54 struct prm_handler_info {
> 55 guid_t guid;
So this should be changed to efi_guid_t.
Doing so makes the following pass:
static_assert(__alignof__(((struct prm_handler_info*)0)->guid) > 1);
(it fails with the original guid_t type)