]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Remove use of EFI_ERROR
authorJan Janssen <medhefgo@web.de>
Fri, 24 Jun 2022 09:00:43 +0000 (11:00 +0200)
committerJan Janssen <medhefgo@web.de>
Mon, 27 Jun 2022 10:16:27 +0000 (12:16 +0200)
The macro is ugly and annoying to use and provides no real benefit. The
only reason to use it would be to allow warnings to go through. But any
EFI APIs we call do not return warning status codes or we do not check
the return value anyway. The only other case would be BS->StartImage,
where we already treat anything other than EFI_SUCCESS as an error
anyway.

This also helps the compiler and code analyzers to better reason about
the code. In particular, this can help reduce use of uninitialized
variable warnings.

18 files changed:
src/boot/efi/boot.c
src/boot/efi/console.c
src/boot/efi/cpio.c
src/boot/efi/devicetree.c
src/boot/efi/drivers.c
src/boot/efi/graphics.c
src/boot/efi/initrd.c
src/boot/efi/linux.c
src/boot/efi/linux_x86.c
src/boot/efi/measure.c
src/boot/efi/pe.c
src/boot/efi/random-seed.c
src/boot/efi/secure-boot.c
src/boot/efi/shim.c
src/boot/efi/splash.c
src/boot/efi/stub.c
src/boot/efi/util.c
src/boot/efi/xbootldr.c

index 0d472b0386dc2cc2247333b9ccf8c6dc72a7e305..f4b987f2f5ed06b4433e06ffef0dc169425bf9cc 100644 (file)
@@ -184,7 +184,7 @@ static BOOLEAN line_edit(
                                 return FALSE;
 
                         print_at(cursor + 1, y_pos, COLOR_EDIT, print + cursor);
-                } while (EFI_ERROR(err));
+                } while (err != EFI_SUCCESS);
 
                 switch (key) {
                 case KEYPRESS(0, SCAN_ESC, 0):
@@ -434,7 +434,7 @@ static BOOLEAN unicode_supported(void) {
         if (cache < 0)
                 /* Basic unicode box drawing support is mandated by the spec, but it does
                  * not hurt to make sure it works. */
-                cache = !EFI_ERROR(ST->ConOut->TestString(ST->ConOut, (CHAR16 *) L"─"));
+                cache = ST->ConOut->TestString(ST->ConOut, (CHAR16 *) L"─") == EFI_SUCCESS;
 
         return cache;
 }
@@ -451,16 +451,14 @@ static void ps_bool(const CHAR16 *fmt, BOOLEAN value) {
 }
 
 static BOOLEAN ps_continue(void) {
-        UINT64 key;
-        EFI_STATUS err;
-
         if (unicode_supported())
                 Print(L"\n─── Press any key to continue, ESC or q to quit. ───\n\n");
         else
                 Print(L"\n--- Press any key to continue, ESC or q to quit. ---\n\n");
 
-        err = console_key_read(&key, UINT64_MAX);
-        return !EFI_ERROR(err) && !IN_SET(key, KEYPRESS(0, SCAN_ESC, 0), KEYPRESS(0, 0, 'q'), KEYPRESS(0, 0, 'Q'));
+        UINT64 key;
+        return console_key_read(&key, UINT64_MAX) == EFI_SUCCESS &&
+                        !IN_SET(key, KEYPRESS(0, SCAN_ESC, 0), KEYPRESS(0, 0, 'q'), KEYPRESS(0, 0, 'Q'));
 }
 
 static void print_status(Config *config, CHAR16 *loaded_image_path) {
@@ -590,7 +588,7 @@ static EFI_STATUS reboot_into_firmware(void) {
         osind |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
 
         err = efivar_set_uint64_le(EFI_GLOBAL_GUID, L"OsIndications", osind, EFI_VARIABLE_NON_VOLATILE);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error setting OsIndications: %r", err);
 
         RT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
@@ -632,7 +630,7 @@ static BOOLEAN menu_run(
 
         err = console_set_mode(config->console_mode_efivar != CONSOLE_MODE_KEEP ?
                                config->console_mode_efivar : config->console_mode);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 clear_screen(COLOR_NORMAL);
                 log_error_stall(L"Error switching console mode: %r", err);
         }
@@ -785,7 +783,7 @@ static BOOLEAN menu_run(
                         /* update status */
                         continue;
                 }
-                if (EFI_ERROR(err)) {
+                if (err != EFI_SUCCESS) {
                         exit = TRUE;
                         break;
                 }
@@ -944,7 +942,7 @@ static BOOLEAN menu_run(
 
                 case KEYPRESS(0, 0, 'r'):
                         err = console_set_mode(CONSOLE_MODE_NEXT);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 status = xpool_print(L"Error changing console mode: %r", err);
                         else {
                                 config->console_mode_efivar = ST->ConOut->Mode->Mode;
@@ -957,7 +955,7 @@ static BOOLEAN menu_run(
                         config->console_mode_efivar = CONSOLE_MODE_KEEP;
                         err = console_set_mode(config->console_mode == CONSOLE_MODE_KEEP ?
                                                console_mode_initial : config->console_mode);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 status = xpool_print(L"Error resetting console mode: %r", err);
                         else
                                 status = xpool_print(L"Console mode reset to %s default.",
@@ -1182,35 +1180,35 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) {
 
                 if (streq8((char *) key, "editor")) {
                         err = parse_boolean(value, &config->editor);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 log_error_stall(L"Error parsing 'editor' config option: %a", value);
                         continue;
                 }
 
                 if (streq8((char *) key, "auto-entries")) {
                         err = parse_boolean(value, &config->auto_entries);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 log_error_stall(L"Error parsing 'auto-entries' config option: %a", value);
                         continue;
                 }
 
                 if (streq8((char *) key, "auto-firmware")) {
                         err = parse_boolean(value, &config->auto_firmware);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 log_error_stall(L"Error parsing 'auto-firmware' config option: %a", value);
                         continue;
                 }
 
                 if (streq8((char *) key, "beep")) {
                         err = parse_boolean(value, &config->beep);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 log_error_stall(L"Error parsing 'beep' config option: %a", value);
                         continue;
                 }
 
                 if (streq8((char *) key, "reboot-for-bitlocker")) {
                         err = parse_boolean(value, &config->reboot_for_bitlocker);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 log_error_stall(L"Error parsing 'reboot-for-bitlocker' config option: %a", value);
                         continue;
                 }
@@ -1244,7 +1242,7 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) {
                                 BOOLEAN on;
 
                                 err = parse_boolean(value, &on);
-                                if (EFI_ERROR(err)) {
+                                if (err != EFI_SUCCESS) {
                                         log_error_stall(L"Error parsing 'random-seed-mode' config option: %a", value);
                                         continue;
                                 }
@@ -1339,17 +1337,17 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
         old_path = xpool_print(L"%s\\%s", entry->path, entry->current_name);
 
         err = root_dir->Open(root_dir, &handle, old_path, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         err = get_file_info_harder(handle, &file_info, &file_info_size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         /* And rename the file */
         strcpy16(file_info->FileName, entry->next_name);
         err = handle->SetInfo(handle, &GenericFileInfo, file_info_size, file_info);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 log_error_stall(L"Failed to rename '%s' to '%s', ignoring: %r", old_path, entry->next_name, err);
                 return;
         }
@@ -1491,7 +1489,7 @@ static void config_entry_add_type1(
         /* check existence */
         _cleanup_(file_closep) EFI_FILE *handle = NULL;
         err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         entry->device = device;
@@ -1525,17 +1523,17 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
         };
 
         err = file_read(root_dir, L"\\loader\\loader.conf", 0, 0, &content, NULL);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 config_defaults_load_from_file(config, content);
 
         err = efivar_get_uint_string(LOADER_GUID, L"LoaderConfigTimeout", &value);
-        if (!EFI_ERROR(err)) {
+        if (err == EFI_SUCCESS) {
                 config->timeout_sec_efivar = MIN(value, TIMEOUT_TYPE_MAX);
                 config->timeout_sec = config->timeout_sec_efivar;
         }
 
         err = efivar_get_uint_string(LOADER_GUID, L"LoaderConfigTimeoutOneShot", &value);
-        if (!EFI_ERROR(err)) {
+        if (err == EFI_SUCCESS) {
                 /* Unset variable now, after all it's "one shot". */
                 (void) efivar_set(LOADER_GUID, L"LoaderConfigTimeoutOneShot", NULL, EFI_VARIABLE_NON_VOLATILE);
 
@@ -1544,11 +1542,11 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
         }
 
         err = efivar_get_uint_string(LOADER_GUID, L"LoaderConfigConsoleMode", &value);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 config->console_mode_efivar = value;
 
         err = efivar_get(LOADER_GUID, L"LoaderEntryOneShot", &config->entry_oneshot);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 /* Unset variable now, after all it's "one shot". */
                 (void) efivar_set(LOADER_GUID, L"LoaderEntryOneShot", NULL, EFI_VARIABLE_NON_VOLATILE);
 
@@ -1583,14 +1581,14 @@ static void config_load_entries(
         /* Adds Boot Loader Type #1 entries (i.e. /loader/entries/….conf) */
 
         err = open_directory(root_dir, L"\\loader\\entries", &entries_dir);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         for (;;) {
                 _cleanup_freepool_ CHAR8 *content = NULL;
 
                 err = readdir_harder(entries_dir, &f, &f_size);
-                if (EFI_ERROR(err) || !f)
+                if (err != EFI_SUCCESS || !f)
                         break;
 
                 if (f->FileName[0] == '.')
@@ -1604,7 +1602,7 @@ static void config_load_entries(
                         continue;
 
                 err = file_read(entries_dir, f->FileName, 0, 0, &content, NULL);
-                if (!EFI_ERROR(err))
+                if (err == EFI_SUCCESS)
                         config_entry_add_type1(config, device, root_dir, L"\\loader\\entries", f->FileName, content, loaded_image_path);
         }
 }
@@ -1814,11 +1812,11 @@ static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const CHAR16 *loader_path) {
         assert(loader_path);
 
         err = pe_file_locate_sections(root_dir, loader_path, sections, &offset, &size);
-        if (EFI_ERROR(err) || size != sizeof(magic))
+        if (err != EFI_SUCCESS || size != sizeof(magic))
                 return FALSE;
 
         err = file_read(root_dir, loader_path, offset, size, &content, &read);
-        if (EFI_ERROR(err) || size != read)
+        if (err != EFI_SUCCESS || size != read)
                 return FALSE;
 
         return memcmp(content, magic, sizeof(magic)) == 0;
@@ -1861,7 +1859,7 @@ static ConfigEntry *config_entry_add_loader_auto(
         /* check existence */
         _cleanup_(file_closep) EFI_FILE *handle = NULL;
         EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return NULL;
 
         ConfigEntry *entry = xnew(ConfigEntry, 1);
@@ -1926,7 +1924,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
                 return EFI_NOT_FOUND;
 
         err = BS->LocateHandleBuffer(ByProtocol, &BlockIoProtocol, NULL, &n_handles, &handles);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Look for BitLocker magic string on all block drives. */
@@ -1934,12 +1932,12 @@ static EFI_STATUS boot_windows_bitlocker(void) {
         for (UINTN i = 0; i < n_handles; i++) {
                 EFI_BLOCK_IO *block_io;
                 err = BS->HandleProtocol(handles[i], &BlockIoProtocol, (void **) &block_io);
-                if (EFI_ERROR(err) || block_io->Media->BlockSize < 512 || block_io->Media->BlockSize > 4096)
+                if (err != EFI_SUCCESS || block_io->Media->BlockSize < 512 || block_io->Media->BlockSize > 4096)
                         continue;
 
                 CHAR8 buf[4096];
                 err = block_io->ReadBlocks(block_io, block_io->Media->MediaId, 0, sizeof(buf), buf);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         continue;
 
                 if (memcmp(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
@@ -1958,7 +1956,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
         /* There can be gaps in Boot#### entries. Instead of iterating over the full
          * EFI var list or UINT16 namespace, just look for "Windows Boot Manager" in BootOrder. */
         err = efivar_get_raw(EFI_GLOBAL_GUID, L"BootOrder", (CHAR8 **) &boot_order, &boot_order_size);
-        if (EFI_ERROR(err) || boot_order_size % sizeof(UINT16) != 0)
+        if (err != EFI_SUCCESS || boot_order_size % sizeof(UINT16) != 0)
                 return err;
 
         for (UINTN i = 0; i < boot_order_size / sizeof(UINT16); i++) {
@@ -1968,7 +1966,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
 
                 SPrint(name, sizeof(name), L"Boot%04x", (UINT32) boot_order[i]);
                 err = efivar_get_raw(EFI_GLOBAL_GUID, name, &buf, &buf_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         continue;
 
                 /* Boot#### are EFI_LOAD_OPTION. But we really are only interested
@@ -1984,7 +1982,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
                                 boot_order + i,
                                 sizeof(boot_order[i]),
                                 EFI_VARIABLE_NON_VOLATILE);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 return err;
                         RT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
                         assert_not_reached();
@@ -2010,7 +2008,7 @@ static void config_entry_add_windows(Config *config, EFI_HANDLE *device, EFI_FIL
 
         /* Try to find a better title. */
         err = file_read(root_dir, L"\\EFI\\Microsoft\\Boot\\BCD", 0, 100*1024, &bcd, &len);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 title = get_bcd_title((UINT8 *) bcd, len);
 
         ConfigEntry *e = config_entry_add_loader_auto(config, device, root_dir, NULL,
@@ -2039,7 +2037,7 @@ static void config_entry_add_unified(
         assert(root_dir);
 
         err = open_directory(root_dir, L"\\EFI\\Linux", &linux_dir);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         for (;;) {
@@ -2066,7 +2064,7 @@ static void config_entry_add_unified(
                 CHAR8 *key, *value;
 
                 err = readdir_harder(linux_dir, &f, &f_size);
-                if (EFI_ERROR(err) || !f)
+                if (err != EFI_SUCCESS || !f)
                         break;
 
                 if (f->FileName[0] == '.')
@@ -2080,11 +2078,11 @@ static void config_entry_add_unified(
 
                 /* look for .osrel and .cmdline sections in the .efi binary */
                 err = pe_file_locate_sections(linux_dir, f->FileName, (const CHAR8**) sections, offs, szs);
-                if (EFI_ERROR(err) || szs[SECTION_OSREL] == 0)
+                if (err != EFI_SUCCESS || szs[SECTION_OSREL] == 0)
                         continue;
 
                 err = file_read(linux_dir, f->FileName, offs[SECTION_OSREL], szs[SECTION_OSREL], &content, NULL);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         continue;
 
                 /* read properties from the embedded os-release file */
@@ -2177,7 +2175,7 @@ static void config_entry_add_unified(
 
                 /* read the embedded cmdline file */
                 err = file_read(linux_dir, f->FileName, offs[SECTION_CMDLINE], szs[SECTION_CMDLINE], &content, NULL);
-                if (!EFI_ERROR(err)) {
+                if (err == EFI_SUCCESS) {
                         /* chomp the newline */
                         if (content[szs[SECTION_CMDLINE] - 1] == '\n')
                                 content[szs[SECTION_CMDLINE] - 1] = '\0';
@@ -2246,12 +2244,12 @@ static EFI_STATUS initrd_prepare(
 
                 _cleanup_(file_closep) EFI_FILE *handle = NULL;
                 err = root->Open(root, &handle, *i, EFI_FILE_MODE_READ, 0);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
                 err = get_file_info_harder(handle, &info, NULL);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 UINTN new_size, read_size = info->FileSize;
@@ -2260,7 +2258,7 @@ static EFI_STATUS initrd_prepare(
                 initrd = xrealloc(initrd, size, new_size);
 
                 err = handle->Read(handle, &read_size, initrd + size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 /* Make sure the actual read size is what we expected. */
@@ -2307,27 +2305,27 @@ static EFI_STATUS image_start(
         _cleanup_freepool_ void *initrd = NULL;
         _cleanup_freepool_ CHAR16 *options_initrd = NULL;
         err = initrd_prepare(image_root, entry, &options_initrd, &initrd, &initrd_size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error preparing initrd: %r", err);
 
         err = BS->LoadImage(FALSE, parent_image, path, NULL, 0, &image);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error loading %s: %r", entry->loader, err);
 
         if (entry->devicetree) {
                 err = devicetree_install(&dtstate, image_root, entry->devicetree);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Error loading %s: %r", entry->devicetree, err);
         }
 
         _cleanup_(cleanup_initrd) EFI_HANDLE initrd_handle = NULL;
         err = initrd_register(initrd, initrd_size, &initrd_handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error registering initrd: %r", err);
 
         EFI_LOADED_IMAGE *loaded_image;
         err = BS->HandleProtocol(image, &LoadedImageProtocol, (void **) &loaded_image);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error getting LoadedImageProtocol handle: %r", err);
 
         CHAR16 *options = options_initrd ?: entry->options;
@@ -2350,7 +2348,7 @@ static EFI_STATUS image_start(
                 UINT32 kernel_entry_address;
 
                 err = pe_alignment_info(loaded_image->ImageBase, &kernel_entry_address, NULL, NULL);
-                if (EFI_ERROR(err)) {
+                if (err != EFI_SUCCESS) {
                         if (err != EFI_UNSUPPORTED)
                                 return log_error_status_stall(err, L"Error finding kernel compat entry address: %r", err);
                 } else {
@@ -2544,7 +2542,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                         image,
                         NULL,
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error getting a LoadedImageProtocol handle: %r", err);
 
         loaded_image_path = DevicePathToStr(loaded_image->FilePath);
@@ -2559,7 +2557,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
         if (secure_boot_enabled() && shim_loaded()) {
                 err = security_policy_install();
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Error installing security policy: %r", err);
         }
 
@@ -2580,7 +2578,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
                 /* Block up to 100ms to give firmware time to get input working. */
                 err = console_key_read(&key, 100 * 1000);
-                if (!EFI_ERROR(err)) {
+                if (err == EFI_SUCCESS) {
                         /* find matching key in config entries */
                         UINTN idx = entry_lookup_key(&config, config.idx_default, KEYCHAR(key));
                         if (idx != IDX_INVALID)
@@ -2615,8 +2613,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
                 err = image_start(image, entry);
                 if (err != EFI_SUCCESS)
-                        /* Not using EFI_ERROR here because positive values are also errors like with any
-                         * other (userspace) program. */
                         goto out;
 
                 menu = TRUE;
index 009d3672b8944948dabbcd45bc0596554ea662c0..f78cfbd7c786b9c0bf34c86da3df420c980c3169 100644 (file)
@@ -49,14 +49,14 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
         if (!checked) {
                 /* Get the *first* TextInputEx device.*/
                 err = BS->LocateProtocol(&SimpleTextInputExProtocol, NULL, (void **) &extraInEx);
-                if (EFI_ERROR(err) || BS->CheckEvent(extraInEx->WaitForKeyEx) == EFI_INVALID_PARAMETER)
+                if (err != EFI_SUCCESS || BS->CheckEvent(extraInEx->WaitForKeyEx) == EFI_INVALID_PARAMETER)
                         /* If WaitForKeyEx fails here, the firmware pretends it talks this
                          * protocol, but it really doesn't. */
                         extraInEx = NULL;
 
                 /* Get the TextInputEx version of ST->ConIn. */
                 err = BS->HandleProtocol(ST->ConsoleInHandle, &SimpleTextInputExProtocol, (void **) &conInEx);
-                if (EFI_ERROR(err) || BS->CheckEvent(conInEx->WaitForKeyEx) == EFI_INVALID_PARAMETER)
+                if (err != EFI_SUCCESS || BS->CheckEvent(conInEx->WaitForKeyEx) == EFI_INVALID_PARAMETER)
                         conInEx = NULL;
 
                 if (conInEx == extraInEx)
@@ -66,7 +66,7 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
         }
 
         err = BS->CreateEvent(EVT_TIMER, 0, NULL, NULL, &timer);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error creating timer event: %r", err);
 
         EFI_EVENT events[] = {
@@ -87,14 +87,14 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
                                 timer,
                                 TimerRelative,
                                 MIN(timeout_usec, watchdog_ping_usec) * 10);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Error arming timer event: %r", err);
 
                 (void) BS->SetWatchdogTimer(watchdog_timeout_sec, 0x10000, 0, NULL);
                 err = BS->WaitForEvent(n_events, events, &index);
                 (void) BS->SetWatchdogTimer(watchdog_timeout_sec, 0x10000, 0, NULL);
 
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Error waiting for events: %r", err);
 
                 /* We have keyboard input, process it after this loop. */
@@ -115,7 +115,7 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
 
         /* If the extra input device we found returns something, always use that instead
          * to work around broken firmware freezing on ConIn/ConInEx. */
-        if (extraInEx && !EFI_ERROR(BS->CheckEvent(extraInEx->WaitForKeyEx))) {
+        if (extraInEx && BS->CheckEvent(extraInEx->WaitForKeyEx) == EFI_SUCCESS) {
                 conInEx = extraInEx;
                 extraInEx = NULL;
         }
@@ -127,7 +127,7 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
                 UINT32 shift = 0;
 
                 err = conInEx->ReadKeyStrokeEx(conInEx, &keydata);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 if (FLAGS_SET(keydata.KeyState.KeyShiftState, EFI_SHIFT_STATE_VALID)) {
@@ -145,11 +145,11 @@ EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec) {
                 /* 32 bit modifier keys + 16 bit scan code + 16 bit unicode */
                 *key = KEYPRESS(shift, keydata.Key.ScanCode, keydata.Key.UnicodeChar);
                 return EFI_SUCCESS;
-        } else if (!EFI_ERROR(BS->CheckEvent(ST->ConIn->WaitForKey))) {
+        } else if (BS->CheckEvent(ST->ConIn->WaitForKey) == EFI_SUCCESS) {
                 EFI_INPUT_KEY k;
 
                 err = ST->ConIn->ReadKeyStroke(ST->ConIn, &k);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 *key = KEYPRESS(0, k.ScanCode, k.UnicodeChar);
@@ -168,11 +168,11 @@ static EFI_STATUS change_mode(INT64 mode) {
         old_mode = MAX(CONSOLE_MODE_RANGE_MIN, ST->ConOut->Mode->Mode);
 
         err = ST->ConOut->SetMode(ST->ConOut, mode);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 return EFI_SUCCESS;
 
         /* Something went wrong. Output is probably borked, so try to revert to previous mode. */
-        if (!EFI_ERROR(ST->ConOut->SetMode(ST->ConOut, old_mode)))
+        if (ST->ConOut->SetMode(ST->ConOut, old_mode) == EFI_SUCCESS)
                 return err;
 
         /* Maybe the device is on fire? */
@@ -186,7 +186,7 @@ EFI_STATUS query_screen_resolution(UINT32 *ret_w, UINT32 *ret_h) {
         EFI_GRAPHICS_OUTPUT_PROTOCOL *go;
 
         err = BS->LocateProtocol(&GraphicsOutputProtocol, NULL, (void **) &go);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         if (!go->Mode || !go->Mode->Info)
@@ -200,7 +200,7 @@ EFI_STATUS query_screen_resolution(UINT32 *ret_w, UINT32 *ret_h) {
 static INT64 get_auto_mode(void) {
         UINT32 screen_width, screen_height;
 
-        if (!EFI_ERROR(query_screen_resolution(&screen_width, &screen_height))) {
+        if (query_screen_resolution(&screen_width, &screen_height) == EFI_SUCCESS) {
                 BOOLEAN keep = FALSE;
 
                 /* Start verifying if we are in a resolution larger than Full HD
@@ -259,7 +259,7 @@ EFI_STATUS console_set_mode(INT64 mode) {
                 mode = MAX(CONSOLE_MODE_RANGE_MIN, ST->ConOut->Mode->Mode);
                 do {
                         mode = (mode + 1) % ST->ConOut->Mode->MaxMode;
-                        if (!EFI_ERROR(change_mode(mode)))
+                        if (change_mode(mode) == EFI_SUCCESS)
                                 break;
                         /* If this mode is broken/unsupported, try the next.
                          * If mode is 0, we wrapped around and should stop. */
@@ -286,7 +286,7 @@ EFI_STATUS console_query_mode(UINTN *x_max, UINTN *y_max) {
         assert(y_max);
 
         err = ST->ConOut->QueryMode(ST->ConOut, ST->ConOut->Mode->Mode, x_max, y_max);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 /* Fallback values mandated by UEFI spec. */
                 switch (ST->ConOut->Mode->Mode) {
                 case CONSOLE_MODE_80_50:
index 454d79e11808cc5066139edf8078ec90ec22bff1..b3f674149e0bedc37a06a0c54c7ed3a344c3baae 100644 (file)
@@ -260,7 +260,7 @@ static EFI_STATUS pack_cpio_prefix(
                                 return EFI_OUT_OF_RESOURCES;
 
                         err = pack_cpio_dir(t, 0555, inode_counter, cpio_buffer, cpio_buffer_size);
-                        if (EFI_ERROR(err))
+                        if (err != EFI_SUCCESS)
                                 return err;
                 }
 
@@ -349,12 +349,12 @@ EFI_STATUS pack_cpio(
                 *ret_buffer_size = 0;
                 return EFI_SUCCESS;
         }
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(
                                 err, L"Unable to load file system protocol: %r", err);
 
         err = volume->OpenVolume(volume, &root);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(
                                 err, L"Unable to open root directory: %r", err);
 
@@ -368,14 +368,14 @@ EFI_STATUS pack_cpio(
                 *ret_buffer_size = 0;
                 return EFI_SUCCESS;
         }
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to open extra directory of loaded image: %r", err);
 
         for (;;) {
                 _cleanup_freepool_ CHAR16 *d = NULL;
 
                 err = readdir_harder(extra_dir, &dirent, &dirent_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Failed to read extra directory of loaded image: %r", err);
                 if (!dirent) /* End of directory */
                         break;
@@ -423,7 +423,7 @@ EFI_STATUS pack_cpio(
         /* Generate the leading directory inodes right before adding the first files, to the
          * archive. Otherwise the cpio archive cannot be unpacked, since the leading dirs won't exist. */
         err = pack_cpio_prefix(target_dir_prefix, dir_mode, &inode, &buffer, &buffer_size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to pack cpio prefix: %r", err);
 
         for (UINTN i = 0; i < n_items; i++) {
@@ -431,7 +431,7 @@ EFI_STATUS pack_cpio(
                 UINTN contentsize;
 
                 err = file_read(extra_dir, items[i], 0, 0, &content, &contentsize);
-                if (EFI_ERROR(err)) {
+                if (err != EFI_SUCCESS) {
                         log_error_status_stall(err, L"Failed to read %s, ignoring: %r", items[i], err);
                         continue;
                 }
@@ -443,12 +443,12 @@ EFI_STATUS pack_cpio(
                                 access_mode,
                                 &inode,
                                 &buffer, &buffer_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Failed to pack cpio file %s: %r", dirent->FileName, err);
         }
 
         err = pack_cpio_trailer(&buffer, &buffer_size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to pack cpio trailer: %r");
 
         for (UINTN i = 0; i < n_tpm_pcr; i++) {
@@ -457,7 +457,7 @@ EFI_STATUS pack_cpio(
                                 POINTER_TO_PHYSICAL_ADDRESS(buffer),
                                 buffer_size,
                                 tpm_description);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         log_error_stall(L"Unable to add initrd TPM measurement for PCR %u (%s), ignoring: %r", tpm_pcr[i], tpm_description, err);
         }
 
index 15513a98e6f4f755c02373e2de089d3fad9b0326..a9b605ae1b16070b741921d4bc6d23c379ba5da1 100644 (file)
@@ -22,7 +22,7 @@ static EFI_STATUS devicetree_allocate(struct devicetree_state *state, UINTN size
         assert(state);
 
         err = BS->AllocatePages(AllocateAnyPages, EfiACPIReclaimMemory, pages, &state->addr);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         state->pages = pages;
@@ -42,7 +42,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
         assert(state);
 
         err = BS->LocateProtocol(&EfiDtFixupProtocol, NULL, (void **) &fixup);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(EFI_SUCCESS,
                                               L"Could not locate device tree fixup protocol, skipping.");
 
@@ -55,12 +55,12 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
                 void *oldptr = PHYSICAL_ADDRESS_TO_POINTER(state->addr);
 
                 err = devicetree_allocate(state, size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), oldptr, len);
                 err = BS->FreePages(oldaddr, oldpages);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 size = devicetree_allocated(state);
@@ -86,11 +86,11 @@ EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir
                 return EFI_UNSUPPORTED;
 
         err = root_dir->Open(root_dir, &handle, name, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = get_file_info_harder(handle, &info, NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (info->FileSize < FDT_V1_SIZE || info->FileSize > 32 * 1024 * 1024)
                 /* 32MB device tree blob doesn't seem right */
@@ -99,15 +99,15 @@ EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir
         len = info->FileSize;
 
         err = devicetree_allocate(state, len);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = handle->Read(handle, &len, PHYSICAL_ADDRESS_TO_POINTER(state->addr));
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = devicetree_fixup(state, len);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         return BS->InstallConfigurationTable(&EfiDtbTableGuid, PHYSICAL_ADDRESS_TO_POINTER(state->addr));
@@ -126,13 +126,13 @@ EFI_STATUS devicetree_install_from_memory(struct devicetree_state *state,
                 return EFI_UNSUPPORTED;
 
         err = devicetree_allocate(state, dtb_length);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), dtb_buffer, dtb_length);
 
         err = devicetree_fixup(state, dtb_length);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         return BS->InstallConfigurationTable(&EfiDtbTableGuid, PHYSICAL_ADDRESS_TO_POINTER(state->addr));
@@ -146,7 +146,7 @@ void devicetree_cleanup(struct devicetree_state *state) {
 
         err = BS->InstallConfigurationTable(&EfiDtbTableGuid, state->orig);
         /* don't free the current device tree if we can't reinstate the old one */
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return;
 
         BS->FreePages(state->addr, state->pages);
index 615c4ca1f3b8cae43a93b506c798f73b7eab4e80..fcc7288533bb506c6170c8d21bfb6dcbdfc855e1 100644 (file)
@@ -26,11 +26,11 @@ static EFI_STATUS load_one_driver(
                 return log_error_status_stall(err, L"Error making file device path: %r", err);
 
         err = BS->LoadImage(FALSE, parent_image, path, NULL, 0, &image);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to load image %s: %r", fname, err);
 
         err = BS->HandleProtocol(image, &LoadedImageProtocol, (void **)&loaded_image);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to find protocol in driver image %s: %r", fname, err);
 
         if (loaded_image->ImageCodeType != EfiBootServicesCode &&
@@ -38,7 +38,7 @@ static EFI_STATUS load_one_driver(
                 return log_error_status_stall(EFI_INVALID_PARAMETER, L"Image %s is not a driver, refusing.", fname);
 
         err = BS->StartImage(image, NULL, NULL);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 /* EFI_ABORTED signals an initializing driver. It uses this error code on success
                  * so that it is unloaded after. */
                 if (err != EFI_ABORTED)
@@ -58,14 +58,14 @@ static EFI_STATUS reconnect(void) {
           /* Reconnects all handles, so that any loaded drivers can take effect. */
 
           err = BS->LocateHandleBuffer(AllHandles, NULL, NULL, &n_handles, &handles);
-          if (EFI_ERROR(err))
+          if (err != EFI_SUCCESS)
                   return log_error_status_stall(err, L"Failed to get list of handles: %r", err);
 
           for (UINTN i = 0; i < n_handles; i++) {
                   err = BS->ConnectController(handles[i], NULL, NULL, TRUE);
                   if (err == EFI_NOT_FOUND) /* No drivers for this handle */
                           continue;
-                  if (EFI_ERROR(err))
+                  if (err != EFI_SUCCESS)
                           log_error_status_stall(err, L"Failed to reconnect handle %" PRIuN L", ignoring: %r", i, err);
           }
 
@@ -88,12 +88,12 @@ EFI_STATUS load_drivers(
                         &drivers_dir);
         if (err == EFI_NOT_FOUND)
                 return EFI_SUCCESS;
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to open \\EFI\\systemd\\drivers: %r", err);
 
         for (;;) {
                 err = readdir_harder(drivers_dir, &dirent, &dirent_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Failed to read extra directory of loaded image: %r", err);
                 if (!dirent) /* End of directory */
                         break;
@@ -106,7 +106,7 @@ EFI_STATUS load_drivers(
                         continue;
 
                 err = load_one_driver(parent_image, loaded_image, dirent->FileName);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         continue;
 
                 n_succeeded++;
index 9e69c2703da172bb52c154787deef1ece984f859..3a1b69016e540c7ce6c2aa743f60f8bd18bd64c2 100644 (file)
@@ -20,13 +20,13 @@ EFI_STATUS graphics_mode(BOOLEAN on) {
         EFI_STATUS err;
 
         err = BS->LocateProtocol((EFI_GUID *) EFI_CONSOLE_CONTROL_GUID, NULL, (void **) &ConsoleControl);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 /* console control protocol is nonstandard and might not exist. */
                 return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
 
         /* check current mode */
         err =ConsoleControl->GetMode(ConsoleControl, &current, &uga_exists, &stdin_locked);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* do not touch the mode */
index 1b4e746483001886a1b74315aa89730188bb24a2..0132c9eddb9d4fdfda930a9c3a656110ce6cc33c 100644 (file)
@@ -102,7 +102,7 @@ EFI_STATUS initrd_register(
                         &DevicePathProtocol, &efi_initrd_device_path,
                         &EfiLoadFile2Protocol, loader,
                         NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 free(loader);
 
         return err;
@@ -119,7 +119,7 @@ EFI_STATUS initrd_unregister(EFI_HANDLE initrd_handle) {
         err = BS->OpenProtocol(
                         initrd_handle, &EfiLoadFile2Protocol, (void **) &loader,
                         NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* close the handle */
@@ -131,7 +131,7 @@ EFI_STATUS initrd_unregister(EFI_HANDLE initrd_handle) {
                         &DevicePathProtocol, &efi_initrd_device_path,
                         &EfiLoadFile2Protocol, loader,
                         NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         initrd_handle = NULL;
index dcffea15c0cdcc1af648db4837907eb87b2952e0..b35c782db2d175441126db0c047d179e8ac2f6ea 100644 (file)
@@ -53,7 +53,7 @@ static EFI_STATUS loaded_image_register(
                         ret_image,
                         &LoadedImageProtocol, loaded_image,
                         NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 loaded_image = loaded_image_free(loaded_image);
 
         return err;
@@ -70,7 +70,7 @@ static EFI_STATUS loaded_image_unregister(EFI_HANDLE loaded_image_handle) {
         err = BS->OpenProtocol(
                         loaded_image_handle, &LoadedImageProtocol, (void **) &loaded_image,
                         NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* close the handle */
@@ -79,7 +79,7 @@ static EFI_STATUS loaded_image_unregister(EFI_HANDLE loaded_image_handle) {
                         loaded_image_handle,
                         &LoadedImageProtocol, loaded_image,
                         NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         loaded_image_handle = NULL;
         loaded_image = loaded_image_free(loaded_image);
@@ -125,7 +125,7 @@ EFI_STATUS linux_exec(
 
         /* get the necessary fields from the PE header */
         err = pe_alignment_info(linux_buffer, &kernel_entry_address, &kernel_size_of_image, &kernel_alignment);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         /* sanity check */
         assert(kernel_size_of_image >= linux_length);
@@ -142,7 +142,7 @@ EFI_STATUS linux_exec(
         /* allocate SizeOfImage + SectionAlignment because the new_buffer can move up to Alignment-1 bytes */
         kernel.num = EFI_SIZE_TO_PAGES(ALIGN_TO(kernel_size_of_image, kernel_alignment) + kernel_alignment);
         err = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, kernel.num, &kernel.addr);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return EFI_OUT_OF_RESOURCES;
         new_buffer = PHYSICAL_ADDRESS_TO_POINTER(ALIGN_TO(kernel.addr, kernel_alignment));
         memcpy(new_buffer, linux_buffer, linux_length);
@@ -154,12 +154,12 @@ EFI_STATUS linux_exec(
 
         /* register a LoadedImage Protocol in order to pass on the commandline */
         err = loaded_image_register(cmdline, cmdline_len, new_buffer, linux_length, &loaded_image_handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* register a LINUX_INITRD_MEDIA DevicePath to serve the initrd */
         err = initrd_register(initrd_buffer, initrd_length, &initrd_handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* call the kernel */
index a6c1f06939561b58b1cc91d4e2e822d6bb98694e..1032b762e531d14033198d2b534c58d417323018 100644 (file)
@@ -155,7 +155,7 @@ EFI_STATUS linux_exec(
                         EfiLoaderData,
                         EFI_SIZE_TO_PAGES(0x4000),
                         &addr);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         boot_params = (struct boot_params *) PHYSICAL_ADDRESS_TO_POINTER(addr);
@@ -173,7 +173,7 @@ EFI_STATUS linux_exec(
                                 EfiLoaderData,
                                 EFI_SIZE_TO_PAGES(cmdline_len + 1),
                                 &addr);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 memcpy(PHYSICAL_ADDRESS_TO_POINTER(addr), cmdline, cmdline_len);
@@ -192,7 +192,7 @@ EFI_STATUS linux_exec(
 
         /* register LINUX_INITRD_MEDIA_GUID */
         err = initrd_register(initrd_buffer, initrd_length, &initrd_handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         linux_efi_handover(image, boot_params);
         (void) initrd_unregister(initrd_handle);
index c31ab5e679e9b23116b37805d61ba09f7866b0e2..2b9ad75aeda98706db9081cfcb4f4b05a289b753 100644 (file)
@@ -87,7 +87,7 @@ static EFI_TCG *tcg1_interface_check(void) {
         EFI_TCG *tcg;
 
         err = BS->LocateProtocol((EFI_GUID *) EFI_TCG_GUID, NULL, (void **) &tcg);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return NULL;
 
         err = tcg->StatusCheck(
@@ -96,7 +96,7 @@ static EFI_TCG *tcg1_interface_check(void) {
                         &features,
                         &event_log_location,
                         &event_log_last_entry);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return NULL;
 
         if (capability.TPMDeactivatedFlag)
@@ -116,11 +116,11 @@ static EFI_TCG2 * tcg2_interface_check(void) {
         EFI_TCG2 *tcg;
 
         err = BS->LocateProtocol((EFI_GUID *) EFI_TCG2_GUID, NULL, (void **) &tcg);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return NULL;
 
         err = tcg->GetCapability(tcg, &capability);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return NULL;
 
         if (capability.StructureVersion.Major == 1 &&
@@ -174,7 +174,7 @@ EFI_STATUS tpm_log_load_options(const CHAR16 *load_options) {
                 err = tpm_log_event(pcr,
                                     POINTER_TO_PHYSICAL_ADDRESS(load_options),
                                     strsize16(load_options), load_options);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Unable to add load options (i.e. kernel command) line measurement to PCR %u: %r", pcr, err);
         }
 
index c1a4064896196f1eb1cd52f09a87ad75be7b91ed..0b486633597d97af6f2c8e2842715ba161ecd650 100644 (file)
@@ -296,23 +296,23 @@ EFI_STATUS pe_file_locate_sections(
         assert(sizes);
 
         err = dir->Open(dir, &handle, (CHAR16*)path, EFI_FILE_MODE_READ, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         len = sizeof(dos);
         err = handle->Read(handle, &len, &dos);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (len != sizeof(dos) || !verify_dos(&dos))
                 return EFI_LOAD_ERROR;
 
         err = handle->SetPosition(handle, dos.ExeHeader);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         len = sizeof(pe);
         err = handle->Read(handle, &len, &pe);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (len != sizeof(pe) || !verify_pe(&pe, /* allow_compatibility= */ FALSE))
                 return EFI_LOAD_ERROR;
@@ -323,12 +323,12 @@ EFI_STATUS pe_file_locate_sections(
                 return EFI_OUT_OF_RESOURCES;
 
         err = handle->SetPosition(handle, section_table_offset(&dos, &pe));
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         len = section_table_len;
         err = handle->Read(handle, &len, section_table);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (len != section_table_len)
                 return EFI_LOAD_ERROR;
index 116ccfe515b53ea10a21d8b2c0cb96d73275c3e2..a1053f9a581309f1fff9f99581b1f0098693f531 100644 (file)
@@ -27,7 +27,7 @@ static EFI_STATUS acquire_rng(UINTN size, void **ret) {
         /* Try to acquire the specified number of bytes from the UEFI RNG */
 
         err = BS->LocateProtocol((EFI_GUID *) EFI_RNG_GUID, NULL, (void **) &rng);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (!rng)
                 return EFI_UNSUPPORTED;
@@ -35,7 +35,7 @@ static EFI_STATUS acquire_rng(UINTN size, void **ret) {
         data = xmalloc(size);
 
         err = rng->GetRNG(rng, NULL, size, data);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to acquire RNG data: %r", err);
 
         *ret = TAKE_PTR(data);
@@ -141,12 +141,12 @@ static EFI_STATUS mangle_random_seed(
 
         /* Begin hashing in counter mode at counter 0 for the new seed for the disk */
         err = hash_many(old_seed, rng, size, system_token, system_token_size, uefi_monotonic_counter, 0, n, &new_seed);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Continue counting at 'n' for the seed for the kernel */
         err = hash_many(old_seed, rng, size, system_token, system_token_size, uefi_monotonic_counter, n, n, &for_kernel);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         *ret_new_seed = TAKE_PTR(new_seed);
@@ -164,7 +164,7 @@ static EFI_STATUS acquire_system_token(void **ret, UINTN *ret_size) {
         assert(ret_size);
 
         err = efivar_get_raw(LOADER_GUID, L"LoaderSystemToken", &data, &size);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 if (err != EFI_NOT_FOUND)
                         log_error_stall(L"Failed to read LoaderSystemToken EFI variable: %r", err);
                 return err;
@@ -253,18 +253,18 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
          * it in our hash. This is protection against golden master image sloppiness, and it remains on the
          * system, even when disk images are duplicated or swapped out. */
         err = acquire_system_token(&system_token, &system_token_size);
-        if (mode != RANDOM_SEED_ALWAYS && EFI_ERROR(err))
+        if (mode != RANDOM_SEED_ALWAYS && err != EFI_SUCCESS)
                 return err;
 
         err = root_dir->Open(root_dir, &handle, (CHAR16*) L"\\loader\\random-seed", EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
-        if (EFI_ERROR(err)) {
+        if (err != EFI_SUCCESS) {
                 if (err != EFI_NOT_FOUND && err != EFI_WRITE_PROTECTED)
                         log_error_stall(L"Failed to open random seed file: %r", err);
                 return err;
         }
 
         err = get_file_info_harder(handle, &info, NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to get file info for random seed: %r");
 
         size = info->FileSize;
@@ -278,13 +278,13 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
 
         rsize = size;
         err = handle->Read(handle, &rsize, seed);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to read random seed file: %r", err);
         if (rsize != size)
                 return log_error_status_stall(EFI_PROTOCOL_ERROR, L"Short read on random seed file.");
 
         err = handle->SetPosition(handle, 0);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to seek to beginning of random seed file: %r", err);
 
         /* Request some random data from the UEFI RNG. We don't need this to work safely, but it's a good
@@ -296,29 +296,29 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
          * boot) in the hash, so that even if the changes to the ESP for some reason should not be
          * persistent, the random seed we generate will still be different on every single boot. */
         err = BS->GetNextMonotonicCount(&uefi_monotonic_counter);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to acquire UEFI monotonic counter: %r", err);
 
         /* Calculate new random seed for the disk and what to pass to the kernel */
         err = mangle_random_seed(seed, rng, size, system_token, system_token_size, uefi_monotonic_counter, &new_seed, &for_kernel);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Update the random seed on disk before we use it */
         wsize = size;
         err = handle->Write(handle, &wsize, new_seed);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to write random seed file: %r", err);
         if (wsize != size)
                 return log_error_status_stall(EFI_PROTOCOL_ERROR, L"Short write on random seed file.");
 
         err = handle->Flush(handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to flush random seed file: %r", err);
 
         /* We are good to go */
         err = efivar_set_raw(LOADER_GUID, L"LoaderRandomSeed", for_kernel, size, 0);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to write random seed to EFI variable: %r", err);
 
         return EFI_SUCCESS;
index 23505d5ae80fedda3abef79b36fa3213583c0d16..c1c1db10b0275ae8b31af64bbd8cc232a4d84423 100644 (file)
@@ -10,7 +10,7 @@ BOOLEAN secure_boot_enabled(void) {
 
         err = efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"SecureBoot", &secure);
 
-        return !EFI_ERROR(err) && secure;
+        return err == EFI_SUCCESS && secure;
 }
 
 SecureBootMode secure_boot_mode(void) {
@@ -18,7 +18,7 @@ SecureBootMode secure_boot_mode(void) {
         EFI_STATUS err;
 
         err = efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"SecureBoot", &secure);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return SECURE_BOOT_UNSUPPORTED;
 
         /* We can assume FALSE for all these if they are abscent (AuditMode and
index 5a6a8bc5b64a7a82d10f735037e7e49cd2c670ba..0df705a331e2d3af93944dc426718894e5d43628 100644 (file)
@@ -37,7 +37,7 @@ struct ShimLock {
 BOOLEAN shim_loaded(void) {
         struct ShimLock *shim_lock;
 
-        return !EFI_ERROR(BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock));
+        return BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock) == EFI_SUCCESS;
 }
 
 static BOOLEAN shim_validate(void *data, UINT32 size) {
@@ -46,13 +46,13 @@ static BOOLEAN shim_validate(void *data, UINT32 size) {
         if (!data)
                 return FALSE;
 
-        if (EFI_ERROR(BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock)))
+        if (BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock) != EFI_SUCCESS)
                 return FALSE;
 
         if (!shim_lock)
                 return FALSE;
 
-        return !EFI_ERROR(shim_lock->shim_verify(data, size));
+        return shim_lock->shim_verify(data, size) == EFI_SUCCESS;
 }
 
 /* Handle to the original authenticator for security1 protocol */
@@ -81,7 +81,7 @@ static EFIAPI EFI_STATUS security2_policy_authentication (const EFI_SECURITY2_PR
         err = es2fa(this, device_path, file_buffer, file_size, boot_policy);
 
         /* if OK, don't bother with MOK check */
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 return err;
 
         if (shim_validate(file_buffer, file_size))
@@ -114,7 +114,7 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
 
         EFI_DEVICE_PATH *dp = (EFI_DEVICE_PATH *) device_path_const;
         err = BS->LocateDevicePath(&FileSystemProtocol, &dp, &h);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         _cleanup_(file_closep) EFI_FILE *root = NULL;
@@ -127,7 +127,7 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
                 return EFI_OUT_OF_RESOURCES;
 
         err = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         if (shim_validate(file_buffer, file_size))
@@ -155,7 +155,7 @@ EFI_STATUS security_policy_install(void) {
 
         err = BS->LocateProtocol((EFI_GUID*) SECURITY_PROTOCOL_GUID, NULL, (void**) &security_protocol);
          /* This one is mandatory, so there's a serious problem */
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         esfas = security_protocol->FileAuthenticationState;
index 2fd2db6ba0b1ca66d10ccc7afa54c310aeb2017f..e2e105b7766356689998b634ed1aaff19a6851cf 100644 (file)
@@ -280,11 +280,11 @@ EFI_STATUS graphics_splash(const UINT8 *content, UINTN len, const EFI_GRAPHICS_O
         }
 
         err = BS->LocateProtocol(&GraphicsOutputProtocol, NULL, (void **) &GraphicsOutput);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = bmp_parse_header(content, len, &dib, &map, &pixmap);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         if (dib->x < GraphicsOutput->Mode->Info->HorizontalResolution)
@@ -297,7 +297,7 @@ EFI_STATUS graphics_splash(const UINT8 *content, UINTN len, const EFI_GRAPHICS_O
                         EfiBltVideoFill, 0, 0, 0, 0,
                         GraphicsOutput->Mode->Info->HorizontalResolution,
                         GraphicsOutput->Mode->Info->VerticalResolution, 0);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* EFI buffer */
@@ -307,15 +307,15 @@ EFI_STATUS graphics_splash(const UINT8 *content, UINTN len, const EFI_GRAPHICS_O
                         GraphicsOutput, blt,
                         EfiBltVideoToBltBuffer, x_pos, y_pos, 0, 0,
                         dib->x, dib->y, 0);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = bmp_to_blt(blt, dib, map, pixmap);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = graphics_mode(TRUE);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         return GraphicsOutput->Blt(
index 9fe521efd40508c7e5c8360cc8561cc42ad56c42..c7ceec3a42060f0ffa8375b5238a0db854d11f09 100644 (file)
@@ -59,7 +59,7 @@ static EFI_STATUS combine_initrd(
                         EfiLoaderData,
                         EFI_SIZE_TO_PAGES(n),
                         &base);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to allocate space for combined initrd: %r", err);
 
         p = PHYSICAL_ADDRESS_TO_POINTER(base);
@@ -192,12 +192,12 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                         image,
                         NULL,
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error getting a LoadedImageProtocol handle: %r", err);
 
         err = pe_memory_locate_sections(loaded_image->ImageBase, (const CHAR8**) sections, addrs, szs);
-        if (EFI_ERROR(err) || szs[SECTION_LINUX] == 0) {
-                if (!EFI_ERROR(err))
+        if (err != EFI_SUCCESS || szs[SECTION_LINUX] == 0) {
+                if (err == EFI_SUCCESS)
                         err = EFI_NOT_FOUND;
                 return log_error_status_stall(err, L"Unable to locate embedded .linux section: %r", err);
         }
@@ -281,7 +281,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                                 global_credential_initrd, global_credential_initrd_size,
                                 sysext_initrd, sysext_initrd_size,
                                 &initrd_base, &initrd_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 /* Given these might be large let's free them explicitly, quickly. */
@@ -293,7 +293,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         if (dt_size > 0) {
                 err = devicetree_install_from_memory(
                                 &dt_state, PHYSICAL_ADDRESS_TO_POINTER(dt_base), dt_size);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         log_error_stall(L"Error loading embedded devicetree: %r", err);
         }
 
index 8ec7e17efc109bc5071a62719873e172b01317da..bddad8eda94be8cec18d4037b1d34cb2392bd499 100644 (file)
@@ -98,7 +98,7 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value
         assert(name);
 
         err = efivar_get_raw(vendor, name, (CHAR8**)&buf, &size);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Make sure there are no incomplete characters in the buffer */
@@ -153,7 +153,7 @@ EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, UINT
         assert(name);
 
         err = efivar_get_raw(vendor, name, &buf, &size);
-        if (!EFI_ERROR(err) && ret) {
+        if (err == EFI_SUCCESS && ret) {
                 if (size != sizeof(UINT32))
                         return EFI_BUFFER_TOO_SMALL;
 
@@ -173,7 +173,7 @@ EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, UINT
         assert(name);
 
         err = efivar_get_raw(vendor, name, &buf, &size);
-        if (!EFI_ERROR(err) && ret) {
+        if (err == EFI_SUCCESS && ret) {
                 if (size != sizeof(UINT64))
                         return EFI_BUFFER_TOO_SMALL;
 
@@ -197,7 +197,7 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **bu
         buf = xmalloc(l);
 
         err = RT->GetVariable((CHAR16 *) name, (EFI_GUID *) vendor, NULL, &l, buf);
-        if (!EFI_ERROR(err)) {
+        if (err == EFI_SUCCESS) {
 
                 if (buffer)
                         *buffer = TAKE_PTR(buf);
@@ -219,7 +219,7 @@ EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const CHAR16 *name, BOO
         assert(ret);
 
         err = efivar_get_raw(vendor, name, &b, &size);
-        if (!EFI_ERROR(err))
+        if (err == EFI_SUCCESS)
                 *ret = *b > 0;
 
         return err;
@@ -374,14 +374,14 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C
         assert(ret);
 
         err = dir->Open(dir, &handle, (CHAR16*) name, EFI_FILE_MODE_READ, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         if (size == 0) {
                 _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
 
                 err = get_file_info_harder(handle, &info, NULL);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
 
                 size = info->FileSize;
@@ -389,7 +389,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C
 
         if (off > 0) {
                 err = handle->SetPosition(handle, off);
-                if (EFI_ERROR(err))
+                if (err != EFI_SUCCESS)
                         return err;
         }
 
@@ -398,7 +398,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C
 
         buf = xmalloc(size + extra);
         err = handle->Read(handle, &size, buf);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Note that handle->Read() changes size to reflect the actually bytes read. */
@@ -499,7 +499,7 @@ EFI_STATUS get_file_info_harder(
                 err = handle->GetInfo(handle, &GenericFileInfo, &size, fi);
         }
 
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         *ret = TAKE_PTR(fi);
@@ -544,7 +544,7 @@ EFI_STATUS readdir_harder(
                 *buffer_size = sz;
                 err = handle->Read(handle, &sz, *buffer);
         }
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         if (sz == 0) {
@@ -593,11 +593,11 @@ EFI_STATUS open_directory(
         /* Opens a file, and then verifies it is actually a directory */
 
         err = root->Open(root, &dir, (CHAR16*) path, EFI_FILE_MODE_READ, 0ULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = get_file_info_harder(dir, &file_info, NULL);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
         if (!FLAGS_SET(file_info->Attribute, EFI_FILE_DIRECTORY))
                 return EFI_LOAD_ERROR;
@@ -614,7 +614,7 @@ UINT64 get_os_indications_supported(void) {
          * supported features. */
 
         err = efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndicationsSupported", &osind);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return 0;
 
         return osind;
index 6e60e4b45df33b60f55d15032b3fe65a68c46d87..1e73b4a65366231f1a2aeb2d6b3f2e2c945251a0 100644 (file)
@@ -65,7 +65,7 @@ static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_
         h->Header.CRC32 = 0;
         err = BS->CalculateCrc32(gpt_header_buffer, h->Header.HeaderSize, &crc32);
         h->Header.CRC32 = crc32_saved;
-        if (EFI_ERROR(err) || crc32 != crc32_saved)
+        if (err != EFI_SUCCESS || crc32 != crc32_saved)
                 return FALSE;
 
         if (h->MyLBA != lba_expected)
@@ -105,7 +105,7 @@ static EFI_STATUS try_gpt(
                         block_io->Media->MediaId,
                         lba,
                         sizeof(gpt), &gpt);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Indicate the location of backup LBA even if the rest of the header is corrupt. */
@@ -124,12 +124,12 @@ static EFI_STATUS try_gpt(
                         block_io->Media->MediaId,
                         gpt.gpt_header.PartitionEntryLBA,
                         size, entries);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Calculate CRC of entries array, too */
         err = BS->CalculateCrc32(entries, size, &crc32);
-        if (EFI_ERROR(err) || crc32 != gpt.gpt_header.PartitionEntryArrayCRC32)
+        if (err != EFI_SUCCESS || crc32 != gpt.gpt_header.PartitionEntryArrayCRC32)
                 return EFI_CRC_ERROR;
 
         /* Now we can finally look for xbootloader partitions. */
@@ -197,11 +197,11 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
         EFI_HANDLE disk_handle;
         EFI_BLOCK_IO *block_io;
         err = BS->LocateDevicePath(&BlockIoProtocol, &p, &disk_handle);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         err = BS->HandleProtocol(disk_handle, &BlockIoProtocol, (void **)&block_io);
-        if (EFI_ERROR(err))
+        if (err != EFI_SUCCESS)
                 return err;
 
         /* Filter out some block devices early. (We only care about block devices that aren't
@@ -234,7 +234,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
                         block_io, lba,
                         nr == 0 ? &backup_lba : NULL, /* Only get backup LBA location from first GPT header. */
                         &hd);
-                if (EFI_ERROR(err)) {
+                if (err != EFI_SUCCESS) {
                         /* GPT was valid but no XBOOT loader partition found. */
                         if (err == EFI_NOT_FOUND)
                                 break;