efi_loader: move dp_alloc() to efi_alloc()

The incumbent function efi_alloc() is unused.

Replace dp_alloc() by a new function efi_alloc() that we can use more
widely.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Heinrich Schuchardt 2023-03-19 09:20:22 +01:00
parent 92b931b8ef
commit f606fab8da
3 changed files with 40 additions and 50 deletions

View file

@ -63,20 +63,6 @@ static bool is_sd(struct blk_desc *desc)
}
#endif
static void *dp_alloc(size_t sz)
{
void *buf;
if (efi_allocate_pool(EFI_BOOT_SERVICES_DATA, sz, &buf) !=
EFI_SUCCESS) {
debug("EFI: ERROR: out of memory in %s\n", __func__);
return NULL;
}
memset(buf, 0, sz);
return buf;
}
/*
* Iterate to next block in device-path, terminating (returning NULL)
* at /End* node.
@ -302,7 +288,7 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
if (!dp)
return NULL;
ndp = dp_alloc(sz);
ndp = efi_alloc(sz);
if (!ndp)
return NULL;
memcpy(ndp, dp, sz);
@ -346,7 +332,7 @@ efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path *dp1,
/* both dp1 and dp2 are non-null */
unsigned sz1 = efi_dp_size(dp1);
unsigned sz2 = efi_dp_size(dp2);
void *p = dp_alloc(sz1 + sz2 + end_size);
void *p = efi_alloc(sz1 + sz2 + end_size);
if (!p)
return NULL;
ret = p;
@ -409,7 +395,7 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
ret = efi_dp_dup(dp);
} else if (!dp) {
size_t sz = node->length;
void *p = dp_alloc(sz + sizeof(END));
void *p = efi_alloc(sz + sizeof(END));
if (!p)
return NULL;
memcpy(p, node, sz);
@ -418,7 +404,7 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
} else {
/* both dp and node are non-null */
size_t sz = efi_dp_size(dp);
void *p = dp_alloc(sz + node->length + sizeof(END));
void *p = efi_alloc(sz + node->length + sizeof(END));
if (!p)
return NULL;
memcpy(p, dp, sz);
@ -439,7 +425,7 @@ struct efi_device_path *efi_dp_create_device_node(const u8 type,
if (length < sizeof(struct efi_device_path))
return NULL;
ret = dp_alloc(length);
ret = efi_alloc(length);
if (!ret)
return ret;
ret->type = type;
@ -461,7 +447,7 @@ struct efi_device_path *efi_dp_append_instance(
return efi_dp_dup(dpi);
sz = efi_dp_size(dp);
szi = efi_dp_instance_size(dpi);
p = dp_alloc(sz + szi + 2 * sizeof(END));
p = efi_alloc(sz + szi + 2 * sizeof(END));
if (!p)
return NULL;
ret = p;
@ -486,7 +472,7 @@ struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
if (!dp || !*dp)
return NULL;
sz = efi_dp_instance_size(*dp);
p = dp_alloc(sz + sizeof(END));
p = efi_alloc(sz + sizeof(END));
if (!p)
return NULL;
memcpy(p, *dp, sz + sizeof(END));
@ -927,7 +913,7 @@ struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
{
void *buf, *start;
start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
start = buf = efi_alloc(dp_part_size(desc, part) + sizeof(END));
if (!buf)
return NULL;
@ -954,7 +940,7 @@ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
dpsize = sizeof(struct efi_device_path_cdrom_path);
else
dpsize = sizeof(struct efi_device_path_hard_drive_path);
buf = dp_alloc(dpsize);
buf = efi_alloc(dpsize);
if (buf)
dp_part_node(buf, desc, part);
@ -1028,7 +1014,7 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
dpsize += fpsize;
start = buf = dp_alloc(dpsize + sizeof(END));
start = buf = efi_alloc(dpsize + sizeof(END));
if (!buf)
return NULL;
@ -1056,7 +1042,7 @@ struct efi_device_path *efi_dp_from_uart(void)
struct efi_device_path_uart *uart;
size_t dpsize = sizeof(ROOT) + sizeof(*uart) + sizeof(END);
buf = dp_alloc(dpsize);
buf = efi_alloc(dpsize);
if (!buf)
return NULL;
pos = buf;
@ -1082,7 +1068,7 @@ struct efi_device_path *efi_dp_from_eth(void)
dpsize += dp_size(eth_get_dev());
start = buf = dp_alloc(dpsize + sizeof(END));
start = buf = efi_alloc(dpsize + sizeof(END));
if (!buf)
return NULL;
@ -1102,7 +1088,7 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
struct efi_device_path_memory *mdp;
void *buf, *start;
start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
start = buf = efi_alloc(sizeof(*mdp) + sizeof(END));
if (!buf)
return NULL;