From 00b87884c4bff63f0bb95547e32b42937e308f53 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 20 Jan 2019 08:33:30 +0000 Subject: [PATCH] uefi: Do not pass required attrs to fwup_delete_variable() This lets us refactor some code and remove some complexity. --- plugins/uefi/efi/fwup-debug.c | 2 +- plugins/uefi/efi/fwup-efi.c | 15 ++++++++++++++- plugins/uefi/efi/fwup-efi.h | 3 +-- plugins/uefi/efi/fwupdate.c | 11 +++-------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/uefi/efi/fwup-debug.c b/plugins/uefi/efi/fwup-debug.c index 0f72ac045..bbb2d0198 100644 --- a/plugins/uefi/efi/fwup-debug.c +++ b/plugins/uefi/efi/fwup-debug.c @@ -35,7 +35,7 @@ fwupd_debug_efivar_append(CHAR16 *out1) static BOOLEAN once = TRUE; if (once) { once = FALSE; - fwup_delete_variable(name, &fwupdate_guid, attrs); + fwup_delete_variable(name, &fwupdate_guid); } else { attrs |= EFI_VARIABLE_APPEND_WRITE; } diff --git a/plugins/uefi/efi/fwup-efi.c b/plugins/uefi/efi/fwup-efi.c index 05e7fa196..8da6b2021 100644 --- a/plugins/uefi/efi/fwup-efi.c +++ b/plugins/uefi/efi/fwup-efi.c @@ -13,8 +13,21 @@ #include "fwup-efi.h" EFI_STATUS -fwup_delete_variable(CHAR16 *name, EFI_GUID *guid, UINT32 attrs) +fwup_delete_variable(CHAR16 *name, EFI_GUID *guid) { + EFI_STATUS rc; + UINT32 attrs = 0; + + /* get the attrs so we can delete it */ + rc = uefi_call_wrapper(RT->GetVariable, 5, name, guid, &attrs, NULL, NULL); + if (EFI_ERROR(rc)) { + if (rc == EFI_NOT_FOUND) { + fwup_debug(L"Not deleting variable '%s' as not found", name); + return EFI_SUCCESS; + } + fwup_debug(L"Could not get variable '%s' for delete: %r", name, rc); + return rc; + } return uefi_call_wrapper(RT->SetVariable, 5, name, guid, attrs, 0, NULL); } diff --git a/plugins/uefi/efi/fwup-efi.h b/plugins/uefi/efi/fwup-efi.h index f7b43b2da..bb2a8092e 100644 --- a/plugins/uefi/efi/fwup-efi.h +++ b/plugins/uefi/efi/fwup-efi.h @@ -57,8 +57,7 @@ typedef struct { } __attribute__((__packed__)) EFI_LOAD_OPTION; EFI_STATUS fwup_delete_variable (CHAR16 *name, - EFI_GUID *guid, - UINT32 attrs); + EFI_GUID *guid); EFI_STATUS fwup_set_variable (CHAR16 *name, EFI_GUID *guid, VOID *data, diff --git a/plugins/uefi/efi/fwupdate.c b/plugins/uefi/efi/fwupdate.c index 143593384..7b294a449 100644 --- a/plugins/uefi/efi/fwupdate.c +++ b/plugins/uefi/efi/fwupdate.c @@ -72,14 +72,12 @@ fwup_populate_update_info(CHAR16 *name, FWUP_UPDATE_TABLE *info_out) if (info_size < sizeof(*info)) { fwup_warning(L"Update '%s' is is too small", name); - fwup_delete_variable(name, &fwupdate_guid, attrs); return EFI_INVALID_PARAMETER; } if (info_size - sizeof(EFI_DEVICE_PATH) <= sizeof(*info)) { fwup_warning(L"Update '%s' is malformed, " L"and cannot hold a file path", name); - fwup_delete_variable(name, &fwupdate_guid, attrs); return EFI_INVALID_PARAMETER; } @@ -89,7 +87,6 @@ fwup_populate_update_info(CHAR16 *name, FWUP_UPDATE_TABLE *info_out) fwup_warning(L"Update '%s' has an invalid file path, " L"device path offset is %d, but total size is %d", name, is, info_size); - fwup_delete_variable(name, &fwupdate_guid, attrs); return EFI_INVALID_PARAMETER; } @@ -99,7 +96,6 @@ fwup_populate_update_info(CHAR16 *name, FWUP_UPDATE_TABLE *info_out) fwup_warning(L"Update '%s' has an invalid file path, " L"update info size: %d dp size: %d size for dp: %d", name, info_size, sz, is); - fwup_delete_variable(name, &fwupdate_guid, attrs); return EFI_INVALID_PARAMETER; } @@ -165,6 +161,7 @@ fwup_populate_update_table(FWUP_UPDATE_TABLE **updates, UINTN *n_updates_out) return EFI_OUT_OF_RESOURCES; rc = fwup_populate_update_info(variable_name, update); if (EFI_ERROR(rc)) { + fwup_delete_variable(variable_name, &fwupdate_guid); fwup_warning(L"Could not populate update info for '%s'", variable_name); return rc; } @@ -431,12 +428,11 @@ fwup_delete_boot_entry(VOID) continue; UINTN info_size = 0; - UINT32 attrs = 0; _cleanup_free VOID *info_ptr = NULL; /* get the data */ rc = fwup_get_variable(variable_name, &vendor_guid, - &info_ptr, &info_size, &attrs); + &info_ptr, &info_size, NULL); if (EFI_ERROR(rc)) return rc; if (info_size < sizeof(EFI_LOAD_OPTION)) @@ -455,8 +451,7 @@ fwup_delete_boot_entry(VOID) fwup_warning(L"Failed to delete boot entry from BootOrder"); return rc; } - rc = fwup_delete_variable(variable_name, - &vendor_guid, attrs); + rc = fwup_delete_variable(variable_name, &vendor_guid); if (EFI_ERROR(rc)) { fwup_warning(L"Failed to delete boot entry"); return rc;