Skip to contentSkip to conversation

efi: Print EFI status as hex number instead of uint

PATCH Superseded Glenn Washburn 3 participants 3 messages Jun 27, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: Print EFI status as hex number instead of uint

EFI status codes are of different classes depending on the first byte and all error status codes defined in appendix D of the main spec start from 1 and have the high bit set. When printing as a uint, the decimal is a very large number that needs have the high bit cleared get the spec error code. This can be easily visually done by a human if the number is printed as hex.

---
 grub-core/loader/efi/linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/efi/linux.c +1 -1
index c1eef7c9865f..ca6f60519d73 100644
@@ -234,7 +234,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   status = b->start_image (image_handle, 0, NULL);
 
   /* When successful, not reached */
-  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %" PRIuGRUB_EFI_UINTN_T, status);
+  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %" PRIxGRUB_EFI_UINTN_T, status);
   grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
 		       GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
 unload:
Signature · 1 line
2.34.1
#1 lore raw
Quoted 17 lines · Glenn Washburn

EFI status codes are of different classes depending on the first byte and all error status codes defined in appendix D of the main spec start from 1 and have the high bit set. When printing as a uint, the decimal is a very large number that needs have the high bit cleared get the spec error code. This can be easily visually done by a human if the number is printed as hex.

---
 grub-core/loader/efi/linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/efi/linux.c +0 -0
index c1eef7c9865f..ca6f60519d73 100644

grub-core/loader/efi/linux.c grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) · line 237

Quoted 5 lines
grub-core/loader/efi/linux.c +1 -1
@@ -234,7 +234,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   status = b->start_image (image_handle, 0, NULL);
 
   /* When successful, not reached */
-  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %" PRIuGRUB_EFI_UINTN_T, status);
+  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %" PRIxGRUB_EFI_UINTN_T, status);

Maybe add the 0x prefix to the format string as well?

Quoted 6 lines
grub-core/loader/efi/linux.c +0 -1
   grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
                       GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
 unload:
--

2.34.1

#2 lore raw
Quoted 25 lines · Ard Biesheuvel
Quoted 3 lines · Glenn Washburn

EFI status codes are of different classes depending on the first byte and all error status codes defined in appendix D of the main spec start from

1

Quoted 2 lines

and have the high bit set. When printing as a uint, the decimal is a very large number that needs have the high bit cleared get the spec error

code.

Quoted 1 line

This can be easily visually done by a human if the number is printed as

hex.

grub-core/loader/efi/linux.c grub_arch_efi_linux_boot_image (grub_addr_t addr,

Quoted 11 lines
---
 grub-core/loader/efi/linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/efi/linux.c +0 -0
index c1eef7c9865f..ca6f60519d73 100644
@@ -234,7 +234,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr,

grub_size_t size, char *args)

Quoted 2 lines
grub-core/loader/efi/linux.c +0 -0
   status = b->start_image (image_handle, 0, NULL);
 
Quoted 8 lines

grub-core/loader/efi/linux.c grub_arch_efi_linux_boot_image (grub_addr_t addr, · line 237

Quoted 2 lines
grub-core/loader/efi/linux.c +0 -1
   /* When successful, not reached */
-  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %"

PRIuGRUB_EFI_UINTN_T, status);

grub-core/loader/efi/linux.c grub_arch_efi_linux_boot_image (grub_addr_t addr, · line 237

Quoted 1 line
grub-core/loader/efi/linux.c +1 -0
+  grub_error (GRUB_ERR_BAD_OS, "start_image() returned %"

PRIxGRUB_EFI_UINTN_T, status);

Maybe add the 0x prefix to the format string as well?

Agreed. Otherwise distinguishing old version with decimal and new with hex from bug reports will be a problem

Quoted 14 lines

grub-core/loader/efi/linux.c grub_arch_efi_linux_boot_image (grub_addr_t addr, · line 239

Quoted 3 lines
grub-core/loader/efi/linux.c +0 -0
   grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
                       GRUB_EFI_BYTES_TO_PAGES

(loaded_image->load_options_size));

Quoted 4 lines
grub-core/loader/efi/linux.c +0 -1
 unload:
--

2.34.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel