uefi: Do not pass required attrs to fwup_delete_variable()

This lets us refactor some code and remove some complexity.
This commit is contained in:
Richard Hughes 2019-01-20 08:33:30 +00:00
parent aa6498866c
commit 00b87884c4
4 changed files with 19 additions and 12 deletions

View File

@ -35,7 +35,7 @@ fwupd_debug_efivar_append(CHAR16 *out1)
static BOOLEAN once = TRUE; static BOOLEAN once = TRUE;
if (once) { if (once) {
once = FALSE; once = FALSE;
fwup_delete_variable(name, &fwupdate_guid, attrs); fwup_delete_variable(name, &fwupdate_guid);
} else { } else {
attrs |= EFI_VARIABLE_APPEND_WRITE; attrs |= EFI_VARIABLE_APPEND_WRITE;
} }

View File

@ -13,8 +13,21 @@
#include "fwup-efi.h" #include "fwup-efi.h"
EFI_STATUS 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); return uefi_call_wrapper(RT->SetVariable, 5, name, guid, attrs, 0, NULL);
} }

View File

@ -57,8 +57,7 @@ typedef struct {
} __attribute__((__packed__)) EFI_LOAD_OPTION; } __attribute__((__packed__)) EFI_LOAD_OPTION;
EFI_STATUS fwup_delete_variable (CHAR16 *name, EFI_STATUS fwup_delete_variable (CHAR16 *name,
EFI_GUID *guid, EFI_GUID *guid);
UINT32 attrs);
EFI_STATUS fwup_set_variable (CHAR16 *name, EFI_STATUS fwup_set_variable (CHAR16 *name,
EFI_GUID *guid, EFI_GUID *guid,
VOID *data, VOID *data,

View File

@ -72,14 +72,12 @@ fwup_populate_update_info(CHAR16 *name, FWUP_UPDATE_TABLE *info_out)
if (info_size < sizeof(*info)) { if (info_size < sizeof(*info)) {
fwup_warning(L"Update '%s' is is too small", name); fwup_warning(L"Update '%s' is is too small", name);
fwup_delete_variable(name, &fwupdate_guid, attrs);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (info_size - sizeof(EFI_DEVICE_PATH) <= sizeof(*info)) { if (info_size - sizeof(EFI_DEVICE_PATH) <= sizeof(*info)) {
fwup_warning(L"Update '%s' is malformed, " fwup_warning(L"Update '%s' is malformed, "
L"and cannot hold a file path", name); L"and cannot hold a file path", name);
fwup_delete_variable(name, &fwupdate_guid, attrs);
return EFI_INVALID_PARAMETER; 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, " fwup_warning(L"Update '%s' has an invalid file path, "
L"device path offset is %d, but total size is %d", L"device path offset is %d, but total size is %d",
name, is, info_size); name, is, info_size);
fwup_delete_variable(name, &fwupdate_guid, attrs);
return EFI_INVALID_PARAMETER; 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, " fwup_warning(L"Update '%s' has an invalid file path, "
L"update info size: %d dp size: %d size for dp: %d", L"update info size: %d dp size: %d size for dp: %d",
name, info_size, sz, is); name, info_size, sz, is);
fwup_delete_variable(name, &fwupdate_guid, attrs);
return EFI_INVALID_PARAMETER; 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; return EFI_OUT_OF_RESOURCES;
rc = fwup_populate_update_info(variable_name, update); rc = fwup_populate_update_info(variable_name, update);
if (EFI_ERROR(rc)) { if (EFI_ERROR(rc)) {
fwup_delete_variable(variable_name, &fwupdate_guid);
fwup_warning(L"Could not populate update info for '%s'", variable_name); fwup_warning(L"Could not populate update info for '%s'", variable_name);
return rc; return rc;
} }
@ -431,12 +428,11 @@ fwup_delete_boot_entry(VOID)
continue; continue;
UINTN info_size = 0; UINTN info_size = 0;
UINT32 attrs = 0;
_cleanup_free VOID *info_ptr = NULL; _cleanup_free VOID *info_ptr = NULL;
/* get the data */ /* get the data */
rc = fwup_get_variable(variable_name, &vendor_guid, rc = fwup_get_variable(variable_name, &vendor_guid,
&info_ptr, &info_size, &attrs); &info_ptr, &info_size, NULL);
if (EFI_ERROR(rc)) if (EFI_ERROR(rc))
return rc; return rc;
if (info_size < sizeof(EFI_LOAD_OPTION)) 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"); fwup_warning(L"Failed to delete boot entry from BootOrder");
return rc; return rc;
} }
rc = fwup_delete_variable(variable_name, rc = fwup_delete_variable(variable_name, &vendor_guid);
&vendor_guid, attrs);
if (EFI_ERROR(rc)) { if (EFI_ERROR(rc)) {
fwup_warning(L"Failed to delete boot entry"); fwup_warning(L"Failed to delete boot entry");
return rc; return rc;