summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2017-04-24 18:44:08 +0300
committerSascha Hauer <s.hauer@pengutronix.de>2017-04-25 07:43:31 +0200
commitb378e8c9427b45d856d052a6df4a879a2cee670c (patch)
tree9635ea41481fe2aab467e9cdb7a10ffe48126c48
parente6cc84d8b751c76571c26e935261fd6f8cac67b7 (diff)
downloadbarebox-b378e8c9427b45d856d052a6df4a879a2cee670c.tar.gz
globalvar: don't use nv_device if CONFIG_NVVAR is disabled
At the moment barebox crashes if CONFIG_NVVAR is disabled because of access to unregistered nv_device in get_param_by_name(&nv_device, "version"). How to reproduce the crash: barebox$ unset ARCH barebox$ unset CROSS_COMPILE barebox$ make sandbox_defconfig barebox$ sed -i "s/CONFIG_ENV_HANDLING=y/# CONFIG_ENV_HANDLING is not set/" .config barebox$ make oldconfig barebox$ ./barebox Segmentation fault Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/globalvar.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/common/globalvar.c b/common/globalvar.c
index 32ca6a2..1ecf513 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -99,6 +99,9 @@ void dev_param_init_from_nv(struct device_d *dev, const char *name)
const char *val;
int ret = 0;
+ if (!IS_ENABLED(CONFIG_NVVAR))
+ return;
+
if (dev == &nv_device)
return;
if (dev == &global_device)
@@ -395,6 +398,9 @@ static void globalvar_nv_sync(const char *name)
{
const char *val;
+ if (!IS_ENABLED(CONFIG_NVVAR))
+ return;
+
val = dev_get_param(&nv_device, name);
if (val)
dev_set_param(&global_device, name, val);
@@ -542,6 +548,8 @@ int nvvar_save(void)
const char *env = default_environment_path_get();
int ret;
#define TMPDIR "/.env.tmp"
+ if (!IS_ENABLED(CONFIG_NVVAR))
+ return -ENOSYS;
if (!nv_dirty || !env)
return 0;
@@ -602,7 +610,9 @@ static int nv_global_param_complete(struct device_d *dev, struct string_list *sl
int nv_global_complete(struct string_list *sl, char *instr)
{
nv_global_param_complete(&global_device, sl, instr, 0);
- nv_global_param_complete(&nv_device, sl, instr, 0);
+
+ if (IS_ENABLED(CONFIG_NVVAR))
+ nv_global_param_complete(&nv_device, sl, instr, 0);
return 0;
}