diff --git a/lib/console.c b/lib/console.c index b02ccb5..d2081ff 100644 --- a/lib/console.c +++ b/lib/console.c @@ -39,14 +39,16 @@ EFI_STATUS console_get_keystroke(EFI_INPUT_KEY *key) { UINTN EventIndex; - EFI_STATUS status; + EFI_STATUS efi_status; do { - uefi_call_wrapper(BS->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &EventIndex); - status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, key); - } while (status == EFI_NOT_READY); + uefi_call_wrapper(BS->WaitForEvent, 3, 1, + &ST->ConIn->WaitForKey, &EventIndex); + efi_status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, + 2, ST->ConIn, key); + } while (efi_status == EFI_NOT_READY); - return status; + return efi_status; } void @@ -183,7 +185,7 @@ console_select(CHAR16 *title[], CHAR16* selectors[], unsigned int start) SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; EFI_INPUT_KEY k; - EFI_STATUS status; + EFI_STATUS efi_status; int selector; unsigned int selector_lines = count_lines(selectors); int selector_max_cols = 0; @@ -236,9 +238,9 @@ console_select(CHAR16 *title[], CHAR16* selectors[], unsigned int start) size_cols, size_rows, 0, lines); do { - status = console_get_keystroke(&k); - if (EFI_ERROR (status)) { - Print(L"Failed to read the keystroke: %r", status); + efi_status = console_get_keystroke(&k); + if (EFI_ERROR (efi_status)) { + Print(L"Failed to read the keystroke: %r", efi_status); selector = -1; break; } @@ -365,13 +367,13 @@ static struct { static CHAR16 * err_string ( - IN EFI_STATUS Status + IN EFI_STATUS efi_status ) { UINTN Index; for (Index = 0; error_table[Index].Desc; Index +=1) { - if (error_table[Index].Code == Status) { + if (error_table[Index].Code == efi_status) { return error_table[Index].Desc; } } @@ -380,7 +382,7 @@ err_string ( } void -console_error(CHAR16 *err, EFI_STATUS status) +console_error(CHAR16 *err, EFI_STATUS efi_status) { CHAR16 **err_arr = (CHAR16 *[]){ L"ERROR", @@ -390,8 +392,8 @@ console_error(CHAR16 *err, EFI_STATUS status) }; CHAR16 str[512]; - SPrint(str, sizeof(str), L"%s: (0x%x) %s", err, status, err_string(status)); - + SPrint(str, sizeof(str), L"%s: (0x%x) %s", err, efi_status, + err_string(efi_status)); err_arr[2] = str; @@ -414,38 +416,38 @@ UINT8 verbose; VOID setup_verbosity(VOID) { - EFI_STATUS status; + EFI_STATUS efi_status; UINT8 verbose_check; UINTN verbose_check_size; verbose_check_size = 1; - status = get_variable(L"SHIM_VERBOSE", (void *)&verbose_check, + efi_status = get_variable(L"SHIM_VERBOSE", (void *)&verbose_check, &verbose_check_size, SHIM_LOCK_GUID); verbose = 0; - if (!EFI_ERROR(status)) + if (!EFI_ERROR(efi_status)) verbose = verbose_check; } VOID setup_console (int text) { - EFI_STATUS status; + EFI_STATUS efi_status; EFI_CONSOLE_CONTROL_PROTOCOL *concon; static EFI_CONSOLE_CONTROL_SCREEN_MODE mode = EfiConsoleControlScreenGraphics; EFI_CONSOLE_CONTROL_SCREEN_MODE new_mode; - status = LibLocateProtocol(&EFI_CONSOLE_CONTROL_GUID, - (VOID **)&concon); - if (status != EFI_SUCCESS) + efi_status = LibLocateProtocol(&EFI_CONSOLE_CONTROL_GUID, + (VOID **)&concon); + if (EFI_ERROR(efi_status)) return; if (text) { new_mode = EfiConsoleControlScreenText; - status = uefi_call_wrapper(concon->GetMode, 4, concon, &mode, - 0, 0); + efi_status = uefi_call_wrapper(concon->GetMode, 4, concon, + &mode, 0, 0); /* If that didn't work, assume it's graphics */ - if (status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) mode = EfiConsoleControlScreenGraphics; } else { new_mode = mode; @@ -463,15 +465,16 @@ print_errors_cb(const char *str, size_t len, void *u) } EFI_STATUS -print_crypto_errors(EFI_STATUS rc, char *file, const char *func, int line) +print_crypto_errors(EFI_STATUS efi_status, + char *file, const char *func, int line) { - if (!(verbose && EFI_ERROR(rc))) - return rc; + if (!(verbose && EFI_ERROR(efi_status))) + return efi_status; - Print(L"SSL Error: %a:%d %a(): %r\n", file, line, func, rc); + Print(L"SSL Error: %a:%d %a(): %r\n", file, line, func, efi_status); ERR_print_errors_cb(print_errors_cb, NULL); - return rc; + return efi_status; } VOID diff --git a/lib/execute.c b/lib/execute.c index 4abccc7..7bd775f 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -95,32 +95,32 @@ error: EFI_STATUS execute(EFI_HANDLE image, CHAR16 *name) { - EFI_STATUS status; + EFI_STATUS efi_status; EFI_HANDLE h; EFI_LOADED_IMAGE *li; EFI_DEVICE_PATH *devpath; CHAR16 *PathName; - status = uefi_call_wrapper(BS->HandleProtocol, 3, image, - &IMAGE_PROTOCOL, (void **)&li); - if (status != EFI_SUCCESS) - return status; + efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, image, + &IMAGE_PROTOCOL, (void **)&li); + if (EFI_ERROR(efi_status)) + return efi_status; - - status = generate_path(name, li, &devpath, &PathName); - if (status != EFI_SUCCESS) - return status; - status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, image, - devpath, NULL, 0, &h); - if (status != EFI_SUCCESS) + efi_status = generate_path(name, li, &devpath, &PathName); + if (EFI_ERROR(efi_status)) + return efi_status; + + efi_status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, image, + devpath, NULL, 0, &h); + if (EFI_ERROR(efi_status)) goto out; - - status = uefi_call_wrapper(BS->StartImage, 3, h, NULL, NULL); + + efi_status = uefi_call_wrapper(BS->StartImage, 3, h, NULL, NULL); uefi_call_wrapper(BS->UnloadImage, 1, h); out: FreePool(PathName); FreePool(devpath); - return status; + return efi_status; } diff --git a/lib/security_policy.c b/lib/security_policy.c index 889653d..a84b057 100644 --- a/lib/security_policy.c +++ b/lib/security_policy.c @@ -80,16 +80,15 @@ security2_policy_authentication ( BOOLEAN BootPolicy ) { - EFI_STATUS status, auth; + EFI_STATUS efi_status, auth; /* Chain original security policy */ - status = uefi_call_wrapper(es2fa, 5, This, DevicePath, FileBuffer, - FileSize, BootPolicy); - + efi_status = uefi_call_wrapper(es2fa, 5, This, DevicePath, FileBuffer, + FileSize, BootPolicy); /* if OK, don't bother with MOK check */ - if (status == EFI_SUCCESS) - return status; + if (!EFI_ERROR(efi_status)) + return efi_status; if (extra_check) auth = extra_check(FileBuffer, FileSize); @@ -100,7 +99,7 @@ security2_policy_authentication ( /* return previous status, which is the correct one * for the platform: may be either EFI_ACCESS_DENIED * or EFI_SECURITY_VIOLATION */ - return status; + return efi_status; return auth; } @@ -112,7 +111,7 @@ security_policy_authentication ( const EFI_DEVICE_PATH_PROTOCOL *DevicePathConst ) { - EFI_STATUS status, fail_status; + EFI_STATUS efi_status, fail_status; EFI_DEVICE_PATH *DevPath = DuplicateDevicePath((EFI_DEVICE_PATH *)DevicePathConst), *OrigDevPath = DevPath; @@ -123,48 +122,48 @@ security_policy_authentication ( CHAR16* DevPathStr; /* Chain original security policy */ - status = uefi_call_wrapper(esfas, 3, This, AuthenticationStatus, - DevicePathConst); - + efi_status = uefi_call_wrapper(esfas, 3, This, AuthenticationStatus, + DevicePathConst); /* if OK avoid checking MOK: It's a bit expensive to * read the whole file in again (esfas already did this) */ - if (status == EFI_SUCCESS) + if (!EFI_ERROR(efi_status)) goto out; /* capture failure status: may be either EFI_ACCESS_DENIED or * EFI_SECURITY_VIOLATION */ - fail_status = status; + fail_status = efi_status; - status = uefi_call_wrapper(BS->LocateDevicePath, 3, - &SIMPLE_FS_PROTOCOL, &DevPath, &h); - if (status != EFI_SUCCESS) + efi_status = uefi_call_wrapper(BS->LocateDevicePath, 3, + &SIMPLE_FS_PROTOCOL, &DevPath, &h); + if (EFI_ERROR(efi_status)) goto out; DevPathStr = DevicePathToStr(DevPath); - status = simple_file_open_by_handle(h, DevPathStr, &f, - EFI_FILE_MODE_READ); + efi_status = simple_file_open_by_handle(h, DevPathStr, &f, + EFI_FILE_MODE_READ); FreePool(DevPathStr); - if (status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) goto out; - status = simple_file_read_all(f, &FileSize, &FileBuffer); + efi_status = simple_file_read_all(f, &FileSize, &FileBuffer); simple_file_close(f); - if (status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) goto out; if (extra_check) - status = extra_check(FileBuffer, FileSize); + efi_status = extra_check(FileBuffer, FileSize); else - status = EFI_SECURITY_VIOLATION; + efi_status = EFI_SECURITY_VIOLATION; FreePool(FileBuffer); - if (status == EFI_ACCESS_DENIED || status == EFI_SECURITY_VIOLATION) + if (efi_status == EFI_ACCESS_DENIED || + efi_status == EFI_SECURITY_VIOLATION) /* return what the platform originally said */ - status = fail_status; + efi_status = fail_status; out: FreePool(OrigDevPath); - return status; + return efi_status; } @@ -265,7 +264,7 @@ security_policy_install(SecurityHook hook) { EFI_SECURITY_PROTOCOL *security_protocol; EFI_SECURITY2_PROTOCOL *security2_protocol = NULL; - EFI_STATUS status; + EFI_STATUS efi_status; if (esfas) /* Already Installed */ @@ -278,16 +277,16 @@ security_policy_install(SecurityHook hook) &SECURITY2_PROTOCOL_GUID, NULL, (VOID **) &security2_protocol); - status = uefi_call_wrapper(BS->LocateProtocol, 3, + efi_status = uefi_call_wrapper(BS->LocateProtocol, 3, &SECURITY_PROTOCOL_GUID, NULL, (VOID **) &security_protocol); - if (status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) /* This one is mandatory, so there's a serious problem */ - return status; + return efi_status; if (security2_protocol) { es2fa = security2_protocol->FileAuthentication; - security2_protocol->FileAuthentication = + security2_protocol->FileAuthentication = (EFI_SECURITY2_FILE_AUTHENTICATION) thunk_security2_policy_authentication; } @@ -304,17 +303,16 @@ security_policy_install(SecurityHook hook) EFI_STATUS security_policy_uninstall(void) { - EFI_STATUS status; + EFI_STATUS efi_status; if (esfas) { EFI_SECURITY_PROTOCOL *security_protocol; - status = uefi_call_wrapper(BS->LocateProtocol, 3, - &SECURITY_PROTOCOL_GUID, NULL, - (VOID **) &security_protocol); - - if (status != EFI_SUCCESS) - return status; + efi_status = uefi_call_wrapper(BS->LocateProtocol, 3, + &SECURITY_PROTOCOL_GUID, NULL, + (VOID **) &security_protocol); + if (EFI_ERROR(efi_status)) + return efi_status; security_protocol->FileAuthenticationState = esfas; esfas = NULL; @@ -326,12 +324,11 @@ security_policy_uninstall(void) if (es2fa) { EFI_SECURITY2_PROTOCOL *security2_protocol; - status = uefi_call_wrapper(BS->LocateProtocol, 3, - &SECURITY2_PROTOCOL_GUID, NULL, - (VOID **) &security2_protocol); - - if (status != EFI_SUCCESS) - return status; + efi_status = uefi_call_wrapper(BS->LocateProtocol, 3, + &SECURITY2_PROTOCOL_GUID, NULL, + (VOID **) &security2_protocol); + if (EFI_ERROR(efi_status)) + return efi_status; security2_protocol->FileAuthentication = es2fa; es2fa = NULL; diff --git a/lib/shell.c b/lib/shell.c index 849f266..224791a 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -14,16 +14,17 @@ EFI_STATUS argsplit(EFI_HANDLE image, int *argc, CHAR16*** ARGV) { unsigned int i, count = 1; - EFI_STATUS status; + EFI_STATUS efi_status; EFI_LOADED_IMAGE *info; CHAR16 *start; *argc = 0; - status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &LoadedImageProtocol, (VOID **) &info); - if (EFI_ERROR(status)) { + efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, image, + &LoadedImageProtocol, (VOID **) &info); + if (EFI_ERROR(efi_status)) { Print(L"Failed to get arguments\n"); - return status; + return efi_status; } for (i = 0; i < info->LoadOptionsSize; i += 2) { diff --git a/lib/simple_file.c b/lib/simple_file.c index e32f78d..7a7625b 100644 --- a/lib/simple_file.c +++ b/lib/simple_file.c @@ -19,14 +19,14 @@ simple_file_open_by_handle(EFI_HANDLE device, CHAR16 *name, EFI_FILE **file, UIN efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, device, &EFI_SIMPLE_FILE_SYSTEM_GUID, (void **)&drive); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Unable to find simple file protocol (%d)\n", efi_status); goto error; } efi_status = uefi_call_wrapper(drive->OpenVolume, 2, drive, &root); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Failed to open drive volume (%d)\n", efi_status); goto error; } @@ -50,12 +50,12 @@ simple_file_open(EFI_HANDLE image, CHAR16 *name, EFI_FILE **file, UINT64 mode) efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &IMAGE_PROTOCOL, (void **)&li); - if (efi_status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) return simple_file_open_by_handle(image, name, file, mode); efi_status = generate_path(name, li, &loadpath, &PathName); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Unable to generate load path for %s\n", name); return efi_status; } @@ -74,28 +74,28 @@ EFI_STATUS simple_dir_read_all_by_handle(EFI_HANDLE image, EFI_FILE *file, CHAR16* name, EFI_FILE_INFO **entries, int *count) { - EFI_STATUS status; + EFI_STATUS efi_status; char buf[4096]; UINTN size = sizeof(buf); EFI_FILE_INFO *fi = (void *)buf; - status = uefi_call_wrapper(file->GetInfo, 4, file, &EFI_FILE_INFO_GUID, - &size, fi); - if (status != EFI_SUCCESS) { + efi_status = uefi_call_wrapper(file->GetInfo, 4, file, &EFI_FILE_INFO_GUID, + &size, fi); + if (EFI_ERROR(efi_status)) { Print(L"Failed to get file info\n"); goto out; } if ((fi->Attribute & EFI_FILE_DIRECTORY) == 0) { Print(L"Not a directory %s\n", name); - status = EFI_INVALID_PARAMETER; + efi_status = EFI_INVALID_PARAMETER; goto out; } size = 0; *count = 0; for (;;) { UINTN len = sizeof(buf); - status = uefi_call_wrapper(file->Read, 3, file, &len, buf); - if (status != EFI_SUCCESS || len == 0) + efi_status = uefi_call_wrapper(file->Read, 3, file, &len, buf); + if (EFI_ERROR(efi_status) || len == 0) break; (*count)++; size += len; @@ -113,14 +113,14 @@ simple_dir_read_all_by_handle(EFI_HANDLE image, EFI_FILE *file, CHAR16* name, EF ptr += len; size -= len; } - status = EFI_SUCCESS; + efi_status = EFI_SUCCESS; out: simple_file_close(file); - if (status != EFI_SUCCESS && *entries) { + if (EFI_ERROR(efi_status) && *entries) { FreePool(*entries); *entries = NULL; } - return status; + return efi_status; } EFI_STATUS @@ -128,12 +128,12 @@ simple_dir_read_all(EFI_HANDLE image, CHAR16 *name, EFI_FILE_INFO **entries, int *count) { EFI_FILE *file; - EFI_STATUS status; + EFI_STATUS efi_status; - status = simple_file_open(image, name, &file, EFI_FILE_MODE_READ); - if (status != EFI_SUCCESS) { - Print(L"failed to open file %s: %d\n", name, status); - return status; + efi_status = simple_file_open(image, name, &file, EFI_FILE_MODE_READ); + if (EFI_ERROR(efi_status)) { + Print(L"failed to open file %s: %d\n", name, efi_status); + return efi_status; } return simple_dir_read_all_by_handle(image, file, name, entries, count); @@ -151,7 +151,7 @@ simple_file_read_all(EFI_FILE *file, UINTN *size, void **buffer) efi_status = uefi_call_wrapper(file->GetInfo, 4, file, &EFI_FILE_INFO_GUID, size, fi); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Failed to get file info\n"); return efi_status; } @@ -190,7 +190,7 @@ simple_volume_selector(CHAR16 **title, CHAR16 **selected, EFI_HANDLE *h) { UINTN count, i; EFI_HANDLE *vol_handles = NULL; - EFI_STATUS status; + EFI_STATUS efi_status; CHAR16 **entries; int val; @@ -212,20 +212,22 @@ simple_volume_selector(CHAR16 **title, CHAR16 **selected, EFI_HANDLE *h) CHAR16 *name; EFI_FILE_IO_INTERFACE *drive; - status = uefi_call_wrapper(BS->HandleProtocol, 3, - vol_handles[i], - &EFI_SIMPLE_FILE_SYSTEM_GUID, - (void **)&drive); - if (status != EFI_SUCCESS || !drive) + efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, + vol_handles[i], + &EFI_SIMPLE_FILE_SYSTEM_GUID, + (void **)&drive); + if (EFI_ERROR(efi_status) || !drive) continue; - status = uefi_call_wrapper(drive->OpenVolume, 2, drive, &root); - if (status != EFI_SUCCESS) + efi_status = uefi_call_wrapper(drive->OpenVolume, 2, drive, + &root); + if (EFI_ERROR(efi_status)) continue; - status = uefi_call_wrapper(root->GetInfo, 4, root, - &EFI_FILE_SYSTEM_INFO_GUID, &size, fi); - if (status != EFI_SUCCESS) + efi_status = uefi_call_wrapper(root->GetInfo, 4, root, + &EFI_FILE_SYSTEM_INFO_GUID, + &size, fi); + if (EFI_ERROR(efi_status)) continue; name = fi->VolumeLabel; @@ -266,7 +268,7 @@ EFI_STATUS simple_dir_filter(EFI_HANDLE image, CHAR16 *name, CHAR16 *filter, CHAR16 ***result, int *count, EFI_FILE_INFO **entries) { - EFI_STATUS status; + EFI_STATUS efi_status; int tot, offs = StrLen(filter), i, c, filtercount = 1; EFI_FILE_INFO *next; void *ptr; @@ -297,8 +299,8 @@ simple_dir_filter(EFI_HANDLE image, CHAR16 *name, CHAR16 *filter, *count = 0; - status = simple_dir_read_all(image, name, entries, &tot); - if (status != EFI_SUCCESS) + efi_status = simple_dir_read_all(image, name, entries, &tot); + if (EFI_ERROR(efi_status)) goto out; ptr = next = *entries; @@ -375,10 +377,10 @@ simple_dir_filter(EFI_HANDLE image, CHAR16 *name, CHAR16 *filter, (*result)[(*count)++] = L"./"; } (*result)[*count] = NULL; - status = EFI_SUCCESS; + efi_status = EFI_SUCCESS; out: - if (status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { if (*entries) FreePool(*entries); *entries = NULL; @@ -386,7 +388,7 @@ simple_dir_filter(EFI_HANDLE image, CHAR16 *name, CHAR16 *filter, FreePool(*result); *result = NULL; } - return status; + return efi_status; } static void @@ -402,7 +404,7 @@ void simple_file_selector(EFI_HANDLE * im, CHAR16 ** title, CHAR16 * name, CHAR16 * filter, CHAR16 ** result) { - EFI_STATUS status; + EFI_STATUS efi_status; CHAR16 **entries = NULL; EFI_FILE_INFO *dmp = NULL; int count, select, len; @@ -432,8 +434,9 @@ simple_file_selector(EFI_HANDLE * im, CHAR16 ** title, CHAR16 * name, name = newname; redo: - status = simple_dir_filter(*im, name, filter, &entries, &count, &dmp); - if (status != EFI_SUCCESS) + efi_status = simple_dir_filter(*im, name, filter, &entries, &count, + &dmp); + if (EFI_ERROR(efi_status)) goto out_free; select = console_select(title, entries, 0); diff --git a/lib/variables.c b/lib/variables.c index 7c28eaa..122a25d 100644 --- a/lib/variables.c +++ b/lib/variables.c @@ -54,7 +54,7 @@ variable_create_esl(void *cert, int cert_len, EFI_GUID *type, EFI_GUID *owner, EFI_STATUS CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data) { - EFI_STATUS Status; + EFI_STATUS efi_status; UINT8 *NewData; UINT8 *Payload; UINTN PayloadSize; @@ -65,12 +65,13 @@ CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data) if (Data == NULL || DataSize == NULL) { return EFI_INVALID_PARAMETER; } - // - // In Setup mode or Custom mode, the variable does not need to be signed but the - // parameters to the SetVariable() call still need to be prepared as authenticated - // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor without certificate - // data in it. - // + /* + * In Setup mode or Custom mode, the variable does not need to be + * signed but the + * parameters to the SetVariable() call still need to be prepared as + * authenticated variable. So we create EFI_VARIABLE_AUTHENTICATED_2 + * descriptor without certificate data in it. + */ Payload = *Data; PayloadSize = *DataSize; @@ -88,10 +89,10 @@ CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data) DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData); ZeroMem(&Time, sizeof(EFI_TIME)); - Status = uefi_call_wrapper(RT->GetTime, 2, &Time, NULL); - if (EFI_ERROR(Status)) { + efi_status = uefi_call_wrapper(RT->GetTime, 2, &Time, NULL); + if (EFI_ERROR(efi_status)) { FreePool(NewData); - return Status; + return efi_status; } Time.Pad1 = 0; Time.Nanosecond = 0; @@ -106,8 +107,10 @@ CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data) DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID; DescriptorData->AuthInfo.CertType = EFI_CERT_TYPE_PKCS7_GUID; - /* we're expecting an EFI signature list, so don't free the input since - * it might not be in a pool */ + /* + * we're expecting an EFI signature list, so don't free the input + * since it might not be in a pool + */ #if 0 if (Payload != NULL) { FreePool(Payload); @@ -137,7 +140,7 @@ SetSecureVariable(CHAR16 *var, UINT8 *Data, UINTN len, EFI_GUID owner, int ds; efi_status = variable_create_esl(Data, len, &X509_GUID, NULL, (void **)&Cert, &ds); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Failed to create %s certificate %d\n", var, efi_status); return efi_status; } @@ -149,7 +152,7 @@ SetSecureVariable(CHAR16 *var, UINT8 *Data, UINTN len, EFI_GUID owner, DataSize = len; } efi_status = CreateTimeBasedPayload(&DataSize, (UINT8 **)&Cert); - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { Print(L"Failed to create time based payload %d\n", efi_status); return efi_status; } @@ -173,7 +176,7 @@ GetOSIndications(void) EFI_STATUS efi_status; efi_status = uefi_call_wrapper(RT->GetVariable, 5, L"OsIndicationsSupported", &GV_GUID, NULL, &DataSize, &indications); - if (efi_status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) return 0; return indications; @@ -188,11 +191,11 @@ SETOSIndicationsAndReboot(UINT64 indications) efi_status = uefi_call_wrapper(RT->SetVariable, 5, L"OsIndications", &GV_GUID, EFI_VARIABLE_NON_VOLATILE - | EFI_VARIABLE_RUNTIME_ACCESS + | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, DataSize, &indications); - if (efi_status != EFI_SUCCESS) + if (EFI_ERROR(efi_status)) return efi_status; uefi_call_wrapper(RT->ResetSystem, 4, EfiResetWarm, EFI_SUCCESS, 0, NULL); @@ -223,8 +226,7 @@ get_variable_attr(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner, efi_status = uefi_call_wrapper(RT->GetVariable, 5, var, &owner, attributes, len, *data); - - if (efi_status != EFI_SUCCESS) { + if (EFI_ERROR(efi_status)) { FreePool(*data); *data = NULL; } @@ -259,17 +261,17 @@ find_in_variable_esl(CHAR16* var, EFI_GUID owner, UINT8 *key, UINTN keylen) { UINTN DataSize = 0; UINT8 *Data = NULL; - EFI_STATUS status; + EFI_STATUS efi_status; - status = get_variable(var, &Data, &DataSize, owner); - if (status != EFI_SUCCESS) - return status; + efi_status = get_variable(var, &Data, &DataSize, owner); + if (EFI_ERROR(efi_status)) + return efi_status; - status = find_in_esl(Data, DataSize, key, keylen); + efi_status = find_in_esl(Data, DataSize, key, keylen); FreePool(Data); - return status; + return efi_status; } int @@ -278,11 +280,11 @@ variable_is_setupmode(int default_return) /* set to 1 because we return true if SetupMode doesn't exist */ UINT8 SetupMode = default_return; UINTN DataSize = sizeof(SetupMode); - EFI_STATUS status; + EFI_STATUS efi_status; - status = uefi_call_wrapper(RT->GetVariable, 5, L"SetupMode", &GV_GUID, NULL, - &DataSize, &SetupMode); - if (EFI_ERROR(status)) + efi_status = uefi_call_wrapper(RT->GetVariable, 5, L"SetupMode", + &GV_GUID, NULL, &DataSize, &SetupMode); + if (EFI_ERROR(efi_status)) return default_return; return SetupMode; @@ -294,12 +296,12 @@ variable_is_secureboot(void) /* return false if variable doesn't exist */ UINT8 SecureBoot = 0; UINTN DataSize; - EFI_STATUS status; + EFI_STATUS efi_status; DataSize = sizeof(SecureBoot); - status = uefi_call_wrapper(RT->GetVariable, 5, L"SecureBoot", &GV_GUID, NULL, - &DataSize, &SecureBoot); - if (EFI_ERROR(status)) + efi_status = uefi_call_wrapper(RT->GetVariable, 5, L"SecureBoot", + &GV_GUID, NULL, &DataSize, &SecureBoot); + if (EFI_ERROR(efi_status)) return 0; return SecureBoot; @@ -309,14 +311,15 @@ EFI_STATUS variable_enroll_hash(CHAR16 *var, EFI_GUID owner, UINT8 hash[SHA256_DIGEST_SIZE]) { - EFI_STATUS status; + EFI_STATUS efi_status; - if (find_in_variable_esl(var, owner, hash, SHA256_DIGEST_SIZE) - == EFI_SUCCESS) + efi_status = find_in_variable_esl(var, owner, hash, SHA256_DIGEST_SIZE); + if (!EFI_ERROR(efi_status)) /* hash already present */ return EFI_ALREADY_STARTED; - UINT8 sig[sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_SIGNATURE_DATA) - 1 + SHA256_DIGEST_SIZE]; + UINT8 sig[sizeof(EFI_SIGNATURE_LIST) + + sizeof(EFI_SIGNATURE_DATA) - 1 + SHA256_DIGEST_SIZE]; EFI_SIGNATURE_LIST *l = (void *)sig; EFI_SIGNATURE_DATA *d = (void *)sig + sizeof(EFI_SIGNATURE_LIST); SetMem(sig, 0, sizeof(sig)); @@ -327,13 +330,13 @@ variable_enroll_hash(CHAR16 *var, EFI_GUID owner, d->SignatureOwner = SHIM_LOCK_GUID; if (CompareGuid(&owner, &SIG_DB) == 0) - status = SetSecureVariable(var, sig, sizeof(sig), owner, - EFI_VARIABLE_APPEND_WRITE, 0); + efi_status = SetSecureVariable(var, sig, sizeof(sig), owner, + EFI_VARIABLE_APPEND_WRITE, 0); else - status = uefi_call_wrapper(RT->SetVariable, 5, var, &owner, - EFI_VARIABLE_NON_VOLATILE - | EFI_VARIABLE_BOOTSERVICE_ACCESS - | EFI_VARIABLE_APPEND_WRITE, - sizeof(sig), sig); - return status; + efi_status = uefi_call_wrapper(RT->SetVariable, 5, var, &owner, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_APPEND_WRITE, + sizeof(sig), sig); + return efi_status; }