[PATCH v2 1/1] 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 --- v2: remove local variable p don' assign unused NULL to var_name16 --- cmd/nvedit_efi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 770877c527..2a5335680c 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -382,8 +382,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, efi_guid_t guid; u32 attributes; bool default_guid, verbose, value_on_memory; - u16 *var_name16 = NULL, *p; - size_t len; + u16 *var_name16; efi_status_t ret;
if (argc == 1) @@ -487,16 +486,12 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, 16, 1, value, size, true); }
- len = utf8_utf16_strnlen(var_name, strlen(var_name)); - var_name16 = malloc((len + 1) * 2); + var_name16 = efi_convert_string(var_name); if (!var_name16) { printf("## Out of memory\n"); ret = CMD_RET_FAILURE; goto out; } - p = var_name16; - utf8_utf16_strncpy(&p, var_name, len + 1); - ret = efi_set_variable_int(var_name16, &guid, attributes, size, value, true); unmap_sysmem(value);

On Thu, 6 Oct 2022 at 14:04, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: remove local variable p don' assign unused NULL to var_name16
cmd/nvedit_efi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 770877c527..2a5335680c 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -382,8 +382,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, efi_guid_t guid; u32 attributes; bool default_guid, verbose, value_on_memory;
u16 *var_name16 = NULL, *p;
size_t len;
u16 *var_name16; efi_status_t ret; if (argc == 1)
@@ -487,16 +486,12 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, 16, 1, value, size, true); }
len = utf8_utf16_strnlen(var_name, strlen(var_name));
var_name16 = malloc((len + 1) * 2);
var_name16 = efi_convert_string(var_name); if (!var_name16) { printf("## Out of memory\n"); ret = CMD_RET_FAILURE; goto out; }
p = var_name16;
utf8_utf16_strncpy(&p, var_name, len + 1);
ret = efi_set_variable_int(var_name16, &guid, attributes, size, value, true); unmap_sysmem(value);
-- 2.37.2
Reviewed-by: Ilias Apalodimas ilias.apalodimas@linaro.org
participants (2)
-
Heinrich Schuchardt
-
Ilias Apalodimas