cmd: simplify do_env_set_efi()
Use efi_convert_string() to convert a UTF-8 to a UTF-16 string. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
parent
39434a9b25
commit
57b2d300af
1 changed files with 3 additions and 8 deletions
|
@ -382,8 +382,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
efi_guid_t guid;
|
efi_guid_t guid;
|
||||||
u32 attributes;
|
u32 attributes;
|
||||||
bool default_guid, verbose, value_on_memory;
|
bool default_guid, verbose, value_on_memory;
|
||||||
u16 *var_name16 = NULL, *p;
|
u16 *var_name16;
|
||||||
size_t len;
|
|
||||||
efi_status_t ret;
|
efi_status_t ret;
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
|
@ -487,18 +486,15 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
16, 1, value, size, true);
|
16, 1, value, size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = utf8_utf16_strnlen(var_name, strlen(var_name));
|
var_name16 = efi_convert_string(var_name);
|
||||||
var_name16 = malloc((len + 1) * 2);
|
|
||||||
if (!var_name16) {
|
if (!var_name16) {
|
||||||
printf("## Out of memory\n");
|
printf("## Out of memory\n");
|
||||||
ret = CMD_RET_FAILURE;
|
ret = CMD_RET_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
p = var_name16;
|
|
||||||
utf8_utf16_strncpy(&p, var_name, len + 1);
|
|
||||||
|
|
||||||
ret = efi_set_variable_int(var_name16, &guid, attributes, size, value,
|
ret = efi_set_variable_int(var_name16, &guid, attributes, size, value,
|
||||||
true);
|
true);
|
||||||
|
free(var_name16);
|
||||||
unmap_sysmem(value);
|
unmap_sysmem(value);
|
||||||
if (ret == EFI_SUCCESS) {
|
if (ret == EFI_SUCCESS) {
|
||||||
ret = CMD_RET_SUCCESS;
|
ret = CMD_RET_SUCCESS;
|
||||||
|
@ -533,7 +529,6 @@ out:
|
||||||
unmap_sysmem(value);
|
unmap_sysmem(value);
|
||||||
else
|
else
|
||||||
free(value);
|
free(value);
|
||||||
free(var_name16);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue