Skip to content

Commit fb98cc0

Browse files
committed
efi: use 32-bit alignment for efi_guid_t literals
Commit 494c704 ("efi: Use 32-bit alignment for efi_guid_t") updated the type definition of efi_guid_t to ensure that it always appears sufficiently aligned (the UEFI spec is ambiguous about this, but given the fact that its EFI_GUID type is defined in terms of a struct carrying a uint32_t, the natural alignment is definitely >= 32 bits). However, we missed the EFI_GUID() macro which is used to instantiate efi_guid_t literals: that macro is still based on the guid_t type, which does not have a minimum alignment at all. This results in warnings such as In file included from drivers/firmware/efi/mokvar-table.c:35: include/linux/efi.h:1093:34: warning: passing 1-byte aligned argument to 4-byte aligned parameter 2 of 'get_var' may result in an unaligned pointer access [-Walign-mismatch] status = get_var(L"SecureBoot", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size, ^ include/linux/efi.h:1101:24: warning: passing 1-byte aligned argument to 4-byte aligned parameter 2 of 'get_var' may result in an unaligned pointer access [-Walign-mismatch] get_var(L"SetupMode", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size, &setupmode); The distinction only matters on CPUs that do not support misaligned loads fully, but 32-bit ARM's load-multiple instructions fall into that category, and these are likely to be emitted by the compiler that built the firmware for loading word-aligned 128-bit GUIDs from memory So re-implement the initializer in terms of our own efi_guid_t type, so that the alignment becomes a property of the literal's type. Fixes: 494c704 ("efi: Use 32-bit alignment for efi_guid_t") Reported-by: Nathan Chancellor <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Link: ClangBuiltLinux#1327 Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 9ceee7d commit fb98cc0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/linux/efi.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ typedef void *efi_handle_t;
7272
*/
7373
typedef guid_t efi_guid_t __aligned(__alignof__(u32));
7474

75-
#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
76-
GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
75+
#define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \
76+
(a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
77+
(b) & 0xff, ((b) >> 8) & 0xff, \
78+
(c) & 0xff, ((c) >> 8) & 0xff, d } }
7779

7880
/*
7981
* Generic EFI table header

0 commit comments

Comments
 (0)