All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] cmd: simplify do_env_set_efi()
@ 2022-10-06  4:54 Heinrich Schuchardt
  2022-10-06  8:03 ` Ilias Apalodimas
  0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2022-10-06  4:54 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 cmd/nvedit_efi.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 770877c527..0411b66559 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -383,7 +383,6 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
 	u32 attributes;
 	bool default_guid, verbose, value_on_memory;
 	u16 *var_name16 = NULL, *p;
-	size_t len;
 	efi_status_t ret;
 
 	if (argc == 1)
@@ -487,16 +486,13 @@ 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] cmd: simplify do_env_set_efi()
  2022-10-06  4:54 [PATCH 1/1] cmd: simplify do_env_set_efi() Heinrich Schuchardt
@ 2022-10-06  8:03 ` Ilias Apalodimas
  0 siblings, 0 replies; 2+ messages in thread
From: Ilias Apalodimas @ 2022-10-06  8:03 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: u-boot

Hi Heinrich, 

On Thu, Oct 06, 2022 at 06:54:19AM +0200, Heinrich Schuchardt wrote:
> Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  cmd/nvedit_efi.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
> index 770877c527..0411b66559 100644
> --- a/cmd/nvedit_efi.c
> +++ b/cmd/nvedit_efi.c
> @@ -383,7 +383,6 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
>  	u32 attributes;
>  	bool default_guid, verbose, value_on_memory;
>  	u16 *var_name16 = NULL, *p;
> -	size_t len;
>  	efi_status_t ret;
>  
>  	if (argc == 1)
> @@ -487,16 +486,13 @@ 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);
> -

Shouldn't we remove p as well after the cleanup ?

>  	ret = efi_set_variable_int(var_name16, &guid, attributes, size, value,
>  				   true);
>  	unmap_sysmem(value);
> -- 
> 2.37.2
> 

Cheers
/Ilias

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-06  8:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  4:54 [PATCH 1/1] cmd: simplify do_env_set_efi() Heinrich Schuchardt
2022-10-06  8:03 ` Ilias Apalodimas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.