mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] globalvar: nv_device fixes
@ 2017-04-24 15:44 Antony Pavlov
  2017-04-24 15:44 ` [PATCH 1/2] globalvar: make nv_device static Antony Pavlov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Antony Pavlov @ 2017-04-24 15:44 UTC (permalink / raw)
  To: barebox

Antony Pavlov (2):
  globalvar: make nv_device static
  globalvar: don't use nv_device if CONFIG_NVVAR is disabled

 common/globalvar.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/2] globalvar: make nv_device static
  2017-04-24 15:44 [PATCH 0/2] globalvar: nv_device fixes Antony Pavlov
@ 2017-04-24 15:44 ` Antony Pavlov
  2017-04-24 15:44 ` [PATCH 2/2] globalvar: don't use nv_device if CONFIG_NVVAR is disabled Antony Pavlov
  2017-04-25  5:43 ` [PATCH 0/2] globalvar: nv_device fixes Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Antony Pavlov @ 2017-04-24 15:44 UTC (permalink / raw)
  To: barebox

nv_device isn't used outside of common/globalvar.c
so make it static.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 common/globalvar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 32ca6a24db..ebc5e830d2 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -19,7 +19,7 @@ struct device_d global_device = {
 	.id = DEVICE_ID_SINGLE,
 };
 
-struct device_d nv_device = {
+static struct device_d nv_device = {
 	.name = "nv",
 	.id = DEVICE_ID_SINGLE,
 };
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] globalvar: don't use nv_device if CONFIG_NVVAR is disabled
  2017-04-24 15:44 [PATCH 0/2] globalvar: nv_device fixes Antony Pavlov
  2017-04-24 15:44 ` [PATCH 1/2] globalvar: make nv_device static Antony Pavlov
@ 2017-04-24 15:44 ` Antony Pavlov
  2017-04-25  5:43 ` [PATCH 0/2] globalvar: nv_device fixes Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Antony Pavlov @ 2017-04-24 15:44 UTC (permalink / raw)
  To: barebox

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>
---
 common/globalvar.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index ebc5e830d2..ff52c9d47f 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;
 }
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 0/2] globalvar: nv_device fixes
  2017-04-24 15:44 [PATCH 0/2] globalvar: nv_device fixes Antony Pavlov
  2017-04-24 15:44 ` [PATCH 1/2] globalvar: make nv_device static Antony Pavlov
  2017-04-24 15:44 ` [PATCH 2/2] globalvar: don't use nv_device if CONFIG_NVVAR is disabled Antony Pavlov
@ 2017-04-25  5:43 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-04-25  5:43 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Mon, Apr 24, 2017 at 06:44:06PM +0300, Antony Pavlov wrote:
> Antony Pavlov (2):
>   globalvar: make nv_device static
>   globalvar: don't use nv_device if CONFIG_NVVAR is disabled
> 
>  common/globalvar.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> -- 
> 2.11.0
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2017-04-25  5:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 15:44 [PATCH 0/2] globalvar: nv_device fixes Antony Pavlov
2017-04-24 15:44 ` [PATCH 1/2] globalvar: make nv_device static Antony Pavlov
2017-04-24 15:44 ` [PATCH 2/2] globalvar: don't use nv_device if CONFIG_NVVAR is disabled Antony Pavlov
2017-04-25  5:43 ` [PATCH 0/2] globalvar: nv_device fixes Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox