nvedit: simplify do_env_indirect()
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>
This commit is contained in:
parent
fef0f1cc38
commit
732b082547
1 changed files with 4 additions and 7 deletions
11
cmd/nvedit.c
11
cmd/nvedit.c
|
@ -1025,6 +1025,7 @@ static int do_env_indirect(struct cmd_tbl *cmdtp, int flag,
|
||||||
char *from = argv[2];
|
char *from = argv[2];
|
||||||
char *default_value = NULL;
|
char *default_value = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
char *val;
|
||||||
|
|
||||||
if (argc < 3 || argc > 4) {
|
if (argc < 3 || argc > 4) {
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -1034,18 +1035,14 @@ static int do_env_indirect(struct cmd_tbl *cmdtp, int flag,
|
||||||
default_value = argv[3];
|
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);
|
printf("## env indirect: Environment variable for <from> (%s) does not exist.\n", from);
|
||||||
|
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env_get(from) == NULL) {
|
ret = env_set(to, val);
|
||||||
ret = env_set(to, default_value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = env_set(to, env_get(from));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
return CMD_RET_SUCCESS;
|
return CMD_RET_SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue