All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvedit: simplify do_env_indirect()
@ 2023-03-06 13:27 Rasmus Villemoes
  2023-03-06 17:53 ` Simon Glass
  2023-03-31 14:16 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2023-03-06 13:27 UTC (permalink / raw)
  To: u-boot; +Cc: Samuel Dionne-Riel, Tom Rini, Rasmus Villemoes

Instead of calling env_get(from) up to three times, just do it once,
computing the value we will put into 'to' and error out if that is
NULL (i.e. no 'from' variable and no default provided).

No functional change.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 cmd/nvedit.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 53e6b57b60..4844eb7f0c 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1026,6 +1026,7 @@ static int do_env_indirect(struct cmd_tbl *cmdtp, int flag,
 	char *from = argv[2];
 	char *default_value = NULL;
 	int ret = 0;
+	char *val;
 
 	if (argc < 3 || argc > 4) {
 		return CMD_RET_USAGE;
@@ -1035,18 +1036,14 @@ static int do_env_indirect(struct cmd_tbl *cmdtp, int flag,
 		default_value = argv[3];
 	}
 
-	if (env_get(from) == NULL && default_value == NULL) {
+	val = env_get(from) ?: default_value;
+	if (!val) {
 		printf("## env indirect: Environment variable for <from> (%s) does not exist.\n", from);
 
 		return CMD_RET_FAILURE;
 	}
 
-	if (env_get(from) == NULL) {
-		ret = env_set(to, default_value);
-	}
-	else {
-		ret = env_set(to, env_get(from));
-	}
+	ret = env_set(to, val);
 
 	if (ret == 0) {
 		return CMD_RET_SUCCESS;
-- 
2.37.2


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

* Re: [PATCH] nvedit: simplify do_env_indirect()
  2023-03-06 13:27 [PATCH] nvedit: simplify do_env_indirect() Rasmus Villemoes
@ 2023-03-06 17:53 ` Simon Glass
  2023-03-31 14:16 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2023-03-06 17:53 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: u-boot, Samuel Dionne-Riel, Tom Rini

On Mon, 6 Mar 2023 at 06:27, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> Instead of calling env_get(from) up to three times, just do it once,
> computing the value we will put into 'to' and error out if that is
> NULL (i.e. no 'from' variable and no default provided).
>
> No functional change.
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>  cmd/nvedit.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* Re: [PATCH] nvedit: simplify do_env_indirect()
  2023-03-06 13:27 [PATCH] nvedit: simplify do_env_indirect() Rasmus Villemoes
  2023-03-06 17:53 ` Simon Glass
@ 2023-03-31 14:16 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2023-03-31 14:16 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: u-boot, Samuel Dionne-Riel

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

On Mon, Mar 06, 2023 at 02:27:21PM +0100, Rasmus Villemoes wrote:

> Instead of calling env_get(from) up to three times, just do it once,
> computing the value we will put into 'to' and error out if that is
> NULL (i.e. no 'from' variable and no default provided).
> 
> No functional change.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

end of thread, other threads:[~2023-03-31 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 13:27 [PATCH] nvedit: simplify do_env_indirect() Rasmus Villemoes
2023-03-06 17:53 ` Simon Glass
2023-03-31 14:16 ` Tom Rini

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.