summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>2023-04-03 16:50:00 +0300
committerTom Rini <trini@konsulko.com>2023-05-04 01:30:46 +0300
commit930ef109928969fa17b8ccf2a05aa4aeff10f3e3 (patch)
tree7d29d44d8dcee0ff2081d043eae3e476f9d621a5 /common
parentd30fbabadebd8b08e2a509a86ff6d4b59ed89f8a (diff)
downloadu-boot-930ef109928969fa17b8ccf2a05aa4aeff10f3e3.tar.xz
common: cli_hush: Restore clear local variable support
The u-boot hush shell doesn’t support the unset command to clear a variable and therefore an empty value ("c=") should be a valid value for the set_local_var function to clear the variable. This partial reverts commit aa722529635c ("common: cli_hush: avoid dead code") and only checks for a `=` in the string. Additionally explicit call the unset_local_var function to remove the variable if the value is empty. Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/cli_hush.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 1ad7a509df..171069f5f4 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -2171,12 +2171,18 @@ int set_local_var(const char *s, int flg_export)
* NAME=VALUE format. So the first order of business is to
* split 's' on the '=' into 'name' and 'value' */
value = strchr(name, '=');
- if (value == NULL || *(value + 1) == 0) {
+ if (!value) {
free(name);
return -1;
}
*value++ = 0;
+ if (!*value) {
+ unset_local_var(name);
+ free(name);
+ return 0;
+ }
+
for(cur = top_vars; cur; cur = cur->next) {
if(strcmp(cur->name, name)==0)
break;