mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 13:41:31 +00:00
efi_loader: simplify efi_allocate_pages()
Replace unnecessary control structures by using return statements. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
parent
f756fe83b0
commit
8ae39857b9
1 changed files with 15 additions and 28 deletions
|
@ -411,7 +411,7 @@ efi_status_t efi_allocate_pages(int type, int memory_type,
|
||||||
efi_uintn_t pages, uint64_t *memory)
|
efi_uintn_t pages, uint64_t *memory)
|
||||||
{
|
{
|
||||||
u64 len = pages << EFI_PAGE_SHIFT;
|
u64 len = pages << EFI_PAGE_SHIFT;
|
||||||
efi_status_t r = EFI_SUCCESS;
|
efi_status_t ret;
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
|
|
||||||
/* Check import parameters */
|
/* Check import parameters */
|
||||||
|
@ -425,48 +425,35 @@ efi_status_t efi_allocate_pages(int type, int memory_type,
|
||||||
case EFI_ALLOCATE_ANY_PAGES:
|
case EFI_ALLOCATE_ANY_PAGES:
|
||||||
/* Any page */
|
/* Any page */
|
||||||
addr = efi_find_free_memory(len, -1ULL);
|
addr = efi_find_free_memory(len, -1ULL);
|
||||||
if (!addr) {
|
if (!addr)
|
||||||
r = EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case EFI_ALLOCATE_MAX_ADDRESS:
|
case EFI_ALLOCATE_MAX_ADDRESS:
|
||||||
/* Max address */
|
/* Max address */
|
||||||
addr = efi_find_free_memory(len, *memory);
|
addr = efi_find_free_memory(len, *memory);
|
||||||
if (!addr) {
|
if (!addr)
|
||||||
r = EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case EFI_ALLOCATE_ADDRESS:
|
case EFI_ALLOCATE_ADDRESS:
|
||||||
/* Exact address, reserve it. The addr is already in *memory. */
|
/* Exact address, reserve it. The addr is already in *memory. */
|
||||||
r = efi_check_allocated(*memory, false);
|
ret = efi_check_allocated(*memory, false);
|
||||||
if (r != EFI_SUCCESS) {
|
if (ret != EFI_SUCCESS)
|
||||||
r = EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
break;
|
|
||||||
}
|
|
||||||
addr = *memory;
|
addr = *memory;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* UEFI doesn't specify other allocation types */
|
/* UEFI doesn't specify other allocation types */
|
||||||
r = EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r == EFI_SUCCESS) {
|
/* Reserve that map in our memory maps */
|
||||||
uint64_t ret;
|
if (efi_add_memory_map(addr, pages, memory_type, true) != addr)
|
||||||
|
/* Map would overlap, bail out */
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
|
||||||
/* Reserve that map in our memory maps */
|
*memory = addr;
|
||||||
ret = efi_add_memory_map(addr, pages, memory_type, true);
|
|
||||||
if (ret == addr) {
|
|
||||||
*memory = addr;
|
|
||||||
} else {
|
|
||||||
/* Map would overlap, bail out */
|
|
||||||
r = EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *efi_alloc(uint64_t len, int memory_type)
|
void *efi_alloc(uint64_t len, int memory_type)
|
||||||
|
|
Loading…
Add table
Reference in a new issue