]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use uintptr_t when converting EFI_PHYSICAL_ADDRESS
authorJan Janssen <medhefgo@web.de>
Tue, 12 Jul 2022 07:43:13 +0000 (09:43 +0200)
committerJan Janssen <medhefgo@web.de>
Tue, 12 Jul 2022 09:24:19 +0000 (11:24 +0200)
uintptr_t is the more appropriate type when casting to/from pointers.

src/boot/efi/util.h

index e314d319614847d9606000492d5d9abfa39edeb1..2cfcda7c622ea0ee8d08ff569fc9850434a623ae 100644 (file)
@@ -144,22 +144,16 @@ EFI_STATUS open_directory(EFI_FILE *root_dir, const char16_t *path, EFI_FILE **r
 
 /* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
  * 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the
- * conversion indirectly: first into UINTN (which is defined by UEFI to have the same size as a pointer), and
- * then extended to EFI_PHYSICAL_ADDRESS. */
+ * conversion indirectly: first into uintptr_t and then extended to EFI_PHYSICAL_ADDRESS. */
 static inline EFI_PHYSICAL_ADDRESS POINTER_TO_PHYSICAL_ADDRESS(const void *p) {
-        return (EFI_PHYSICAL_ADDRESS) (UINTN) p;
+        return (EFI_PHYSICAL_ADDRESS) (uintptr_t) p;
 }
 
 static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) {
-#if __SIZEOF_POINTER__ == 4
         /* On 32bit systems the address might not be convertible (as pointers are 32bit but
          * EFI_PHYSICAL_ADDRESS 64bit) */
-        assert(addr <= UINT32_MAX);
-#elif __SIZEOF_POINTER__ != 8
-        #error "Unexpected pointer size"
-#endif
-
-        return (void*) (UINTN) addr;
+        assert(addr <= UINTPTR_MAX);
+        return (void *) (uintptr_t) addr;
 }
 
 uint64_t get_os_indications_supported(void);