mirror of
https://xff.cz/git/u-boot/
synced 2025-09-02 09:12:08 +02:00
eficonfig: carve out efi_get_next_variable_name_int calls
To retrieve the EFI variable name by efi_get_next_variable_name_int(), the sequence of alloc -> efi_get_next_variable_name_int -> realloc -> efi_get_next_variable_name_int is required. In current code, this sequence repeatedly appears in the several functions. It should be curved out a common function. This commit also fixes the missing free() of var_name16 in eficonfig_delete_invalid_boot_option(). Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
committed by
Heinrich Schuchardt
parent
f823e32388
commit
ce3270849b
@@ -1683,7 +1683,7 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected)
|
|||||||
u32 i;
|
u32 i;
|
||||||
u16 *bootorder;
|
u16 *bootorder;
|
||||||
efi_status_t ret;
|
efi_status_t ret;
|
||||||
u16 *var_name16 = NULL, *p;
|
u16 *var_name16 = NULL;
|
||||||
efi_uintn_t num, size, buf_size;
|
efi_uintn_t num, size, buf_size;
|
||||||
struct efimenu *efi_menu;
|
struct efimenu *efi_menu;
|
||||||
struct list_head *pos, *n;
|
struct list_head *pos, *n;
|
||||||
@@ -1718,24 +1718,12 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected)
|
|||||||
int index;
|
int index;
|
||||||
efi_guid_t guid;
|
efi_guid_t guid;
|
||||||
|
|
||||||
size = buf_size;
|
ret = efi_next_variable_name(&buf_size, &var_name16, &guid);
|
||||||
ret = efi_get_next_variable_name_int(&size, var_name16, &guid);
|
|
||||||
if (ret == EFI_NOT_FOUND)
|
if (ret == EFI_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
if (ret == EFI_BUFFER_TOO_SMALL) {
|
if (ret != EFI_SUCCESS)
|
||||||
buf_size = size;
|
goto out;
|
||||||
p = realloc(var_name16, buf_size);
|
|
||||||
if (!p) {
|
|
||||||
free(var_name16);
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
var_name16 = p;
|
|
||||||
ret = efi_get_next_variable_name_int(&size, var_name16, &guid);
|
|
||||||
}
|
|
||||||
if (ret != EFI_SUCCESS) {
|
|
||||||
free(var_name16);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (efi_varname_is_load_option(var_name16, &index)) {
|
if (efi_varname_is_load_option(var_name16, &index)) {
|
||||||
/* If the index is included in the BootOrder, skip it */
|
/* If the index is included in the BootOrder, skip it */
|
||||||
if (search_bootorder(bootorder, num, index, NULL))
|
if (search_bootorder(bootorder, num, index, NULL))
|
||||||
@@ -2026,7 +2014,7 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi
|
|||||||
u32 i;
|
u32 i;
|
||||||
char *title;
|
char *title;
|
||||||
efi_status_t ret;
|
efi_status_t ret;
|
||||||
u16 *var_name16 = NULL, *p;
|
u16 *var_name16 = NULL;
|
||||||
efi_uintn_t size, buf_size;
|
efi_uintn_t size, buf_size;
|
||||||
|
|
||||||
/* list the load option in the order of BootOrder variable */
|
/* list the load option in the order of BootOrder variable */
|
||||||
@@ -2054,19 +2042,9 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
size = buf_size;
|
size = buf_size;
|
||||||
ret = efi_get_next_variable_name_int(&size, var_name16, &guid);
|
ret = efi_next_variable_name(&buf_size, &var_name16, &guid);
|
||||||
if (ret == EFI_NOT_FOUND)
|
if (ret == EFI_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
if (ret == EFI_BUFFER_TOO_SMALL) {
|
|
||||||
buf_size = size;
|
|
||||||
p = realloc(var_name16, buf_size);
|
|
||||||
if (!p) {
|
|
||||||
ret = EFI_OUT_OF_RESOURCES;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
var_name16 = p;
|
|
||||||
ret = efi_get_next_variable_name_int(&size, var_name16, &guid);
|
|
||||||
}
|
|
||||||
if (ret != EFI_SUCCESS)
|
if (ret != EFI_SUCCESS)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@@ -2336,10 +2314,10 @@ efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_op
|
|||||||
efi_uintn_t size;
|
efi_uintn_t size;
|
||||||
void *load_option;
|
void *load_option;
|
||||||
struct efi_load_option lo;
|
struct efi_load_option lo;
|
||||||
u16 *var_name16 = NULL, *p;
|
u16 *var_name16 = NULL;
|
||||||
u16 varname[] = u"Boot####";
|
u16 varname[] = u"Boot####";
|
||||||
efi_status_t ret = EFI_SUCCESS;
|
efi_status_t ret = EFI_SUCCESS;
|
||||||
efi_uintn_t varname_size, buf_size;
|
efi_uintn_t buf_size;
|
||||||
|
|
||||||
buf_size = 128;
|
buf_size = 128;
|
||||||
var_name16 = malloc(buf_size);
|
var_name16 = malloc(buf_size);
|
||||||
@@ -2352,24 +2330,12 @@ efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_op
|
|||||||
efi_guid_t guid;
|
efi_guid_t guid;
|
||||||
efi_uintn_t tmp;
|
efi_uintn_t tmp;
|
||||||
|
|
||||||
varname_size = buf_size;
|
ret = efi_next_variable_name(&buf_size, &var_name16, &guid);
|
||||||
ret = efi_get_next_variable_name_int(&varname_size, var_name16, &guid);
|
|
||||||
if (ret == EFI_NOT_FOUND)
|
if (ret == EFI_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
if (ret == EFI_BUFFER_TOO_SMALL) {
|
if (ret != EFI_SUCCESS)
|
||||||
buf_size = varname_size;
|
goto out;
|
||||||
p = realloc(var_name16, buf_size);
|
|
||||||
if (!p) {
|
|
||||||
free(var_name16);
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
var_name16 = p;
|
|
||||||
ret = efi_get_next_variable_name_int(&varname_size, var_name16, &guid);
|
|
||||||
}
|
|
||||||
if (ret != EFI_SUCCESS) {
|
|
||||||
free(var_name16);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (!efi_varname_is_load_option(var_name16, &index))
|
if (!efi_varname_is_load_option(var_name16, &index))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -2407,6 +2373,8 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
free(var_name16);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -708,6 +708,8 @@ int algo_to_len(const char *algo);
|
|||||||
int efi_link_dev(efi_handle_t handle, struct udevice *dev);
|
int efi_link_dev(efi_handle_t handle, struct udevice *dev);
|
||||||
int efi_unlink_dev(efi_handle_t handle);
|
int efi_unlink_dev(efi_handle_t handle);
|
||||||
bool efi_varname_is_load_option(u16 *var_name16, int *index);
|
bool efi_varname_is_load_option(u16 *var_name16, int *index);
|
||||||
|
efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
|
||||||
|
efi_guid_t *guid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* efi_size_in_pages() - convert size in bytes to size in pages
|
* efi_size_in_pages() - convert size in bytes to size in pages
|
||||||
|
@@ -223,3 +223,37 @@ bool efi_varname_is_load_option(u16 *var_name16, int *index)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* efi_next_variable_name() - get next variable name
|
||||||
|
*
|
||||||
|
* This function is a wrapper of efi_get_next_variable_name_int().
|
||||||
|
* If efi_get_next_variable_name_int() returns EFI_BUFFER_TOO_SMALL,
|
||||||
|
* @size and @buf are updated by new buffer size and realloced buffer.
|
||||||
|
*
|
||||||
|
* @size: pointer to the buffer size
|
||||||
|
* @buf: pointer to the buffer
|
||||||
|
* @guid: pointer to the guid
|
||||||
|
* Return: status code
|
||||||
|
*/
|
||||||
|
efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, efi_guid_t *guid)
|
||||||
|
{
|
||||||
|
u16 *p;
|
||||||
|
efi_status_t ret;
|
||||||
|
efi_uintn_t buf_size = *size;
|
||||||
|
|
||||||
|
ret = efi_get_next_variable_name_int(&buf_size, *buf, guid);
|
||||||
|
if (ret == EFI_NOT_FOUND)
|
||||||
|
return ret;
|
||||||
|
if (ret == EFI_BUFFER_TOO_SMALL) {
|
||||||
|
p = realloc(*buf, buf_size);
|
||||||
|
if (!p)
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
|
||||||
|
*buf = p;
|
||||||
|
*size = buf_size;
|
||||||
|
ret = efi_get_next_variable_name_int(&buf_size, *buf, guid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user