summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-11-05 10:33:37 -0700
committerTom Rini <trini@konsulko.com>2020-12-04 16:09:06 -0500
commit96434a76fd254248ded19e95dc967d28e65a5edf (patch)
treef7bcdd880ec983c695273b842276bda423a72741 /cmd
parent4c450daf7d5d48ef075980e11052bf6bb28db4f6 (diff)
downloadu-boot-96434a76fd254248ded19e95dc967d28e65a5edf.tar.gz
u-boot-96434a76fd254248ded19e95dc967d28e65a5edf.tar.xz
u-boot-96434a76fd254248ded19e95dc967d28e65a5edf.zip
env: Allow returning errors from hdelete_r()
At present this function returns 1 on success and 0 on failure. But in the latter case it provides no indication of what went wrong. If an attempt is made to delete a non-existent variable, the caller may want to ignore this error. This happens when setting a non-existent variable to "", for example. Update the function to return 0 on success and a useful error code on failure. Add a function comment too. Make sure that env_set() does not return an error if it is deleting a variable that doesn't exist. We could update env_set() to return useful error numbers also, but that is beyond the scope of this change. Signed-off-by: Simon Glass <sjg@chromium.org> wip
Diffstat (limited to 'cmd')
-rw-r--r--cmd/nvedit.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 7fce723800..d0d2eca904 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -266,7 +266,9 @@ static int _do_env_set(int flag, int argc, char *const argv[], int env_flag)
/* Delete only ? */
if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, &env_htab, env_flag);
- return !rc;
+
+ /* If the variable didn't exist, don't report an error */
+ return rc && rc != -ENOENT ? 1 : 0;
}
/*
@@ -895,7 +897,7 @@ static int do_env_delete(struct cmd_tbl *cmdtp, int flag,
while (--argc > 0) {
char *name = *++argv;
- if (!hdelete_r(name, &env_htab, env_flag))
+ if (hdelete_r(name, &env_htab, env_flag))
ret = 1;
}