2017-04-28 09:44:01

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH 1/2] of: fix uninitialized variable warning for overlay test

gcc warns that an empty device tree would cause undefined behavior:

drivers/of/unittest.c: In function 'of_unittest':
drivers/of/unittest.c:2199:25: warning: 'last_sibling' may be used uninitialized in this function [-Wmaybe-uninitialized]

This adds an initialization of the variable to zero, which we handle
correctly.

Fixes: 81d0848fc8d2 ("of: Add unit tests for applying overlays")
Signed-off-by: Arnd Bergmann <[email protected]>
---
drivers/of/unittest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 12597ff8cfb0..6b8f3e6aa43c 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2192,7 +2192,7 @@ static __init void of_unittest_overlay_high_level(void)

mutex_lock(&of_mutex);

- for (np = of_root->child; np; np = np->sibling)
+ for (last_sibling = np = of_root->child; np; np = np->sibling)
last_sibling = np;

if (last_sibling)
--
2.9.0


2017-04-28 09:44:20

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH 2/2] of: fix unittest build without CONFIG_OF_OVERLAY

We get a link error when the new tests are used by overlays
are not:

drivers/of/built-in.o: In function `unflatten_device_tree':
(.init.text+0x967): undefined reference to `unittest_unflatten_overlay_base'

This makes the #ifdef check match the symbols that lead to building
the unittest_unflatten_overlay_base function.

Fixes: 81d0848fc8d2 ("of: Add unit tests for applying overlays")
Signed-off-by: Arnd Bergmann <[email protected]>
---
drivers/of/of_private.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index de5c604f5cc4..4ebb0149d118 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -55,7 +55,7 @@ static inline int of_property_notify(int action, struct device_node *np,
}
#endif /* CONFIG_OF_DYNAMIC */

-#ifdef CONFIG_OF_UNITTEST
+#if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
extern void __init unittest_unflatten_overlay_base(void);
#else
static inline void unittest_unflatten_overlay_base(void) {};
--
2.9.0

2017-04-28 15:41:31

by Frank Rowand

[permalink] [raw]
Subject: Re: [PATCH 2/2] of: fix unittest build without CONFIG_OF_OVERLAY

On 04/28/17 02:44, Arnd Bergmann wrote:
> We get a link error when the new tests are used by overlays
> are not:
>
> drivers/of/built-in.o: In function `unflatten_device_tree':
> (.init.text+0x967): undefined reference to `unittest_unflatten_overlay_base'
>
> This makes the #ifdef check match the symbols that lead to building
> the unittest_unflatten_overlay_base function.
>
> Fixes: 81d0848fc8d2 ("of: Add unit tests for applying overlays")
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> drivers/of/of_private.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
> index de5c604f5cc4..4ebb0149d118 100644
> --- a/drivers/of/of_private.h
> +++ b/drivers/of/of_private.h
> @@ -55,7 +55,7 @@ static inline int of_property_notify(int action, struct device_node *np,
> }
> #endif /* CONFIG_OF_DYNAMIC */
>
> -#ifdef CONFIG_OF_UNITTEST
> +#if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
> extern void __init unittest_unflatten_overlay_base(void);
> #else
> static inline void unittest_unflatten_overlay_base(void) {};
>

I thought I had tested that OF_UNITTEST forced OF_OVERLAY. But
going back and trying again, I can confirm your results that it
does not. Thanks for catching this!

Reviewed-by: Frank Rowand <[email protected]>
Tested-by: Frank Rowand <[email protected]>

-Frank

2017-04-28 15:46:57

by Frank Rowand

[permalink] [raw]
Subject: Re: [PATCH 1/2] of: fix uninitialized variable warning for overlay test

On 04/28/17 02:44, Arnd Bergmann wrote:
> gcc warns that an empty device tree would cause undefined behavior:
>
> drivers/of/unittest.c: In function 'of_unittest':
> drivers/of/unittest.c:2199:25: warning: 'last_sibling' may be used uninitialized in this function [-Wmaybe-uninitialized]
>
> This adds an initialization of the variable to zero, which we handle
> correctly.
>
> Fixes: 81d0848fc8d2 ("of: Add unit tests for applying overlays")
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> drivers/of/unittest.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 12597ff8cfb0..6b8f3e6aa43c 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -2192,7 +2192,7 @@ static __init void of_unittest_overlay_high_level(void)
>
> mutex_lock(&of_mutex);
>
> - for (np = of_root->child; np; np = np->sibling)
> + for (last_sibling = np = of_root->child; np; np = np->sibling)
> last_sibling = np;
>
> if (last_sibling)
>

Thanks Arnd! Linux-next also reported this and I sent Rob a different
patch for it yesterday.

Rob, I am fine with either Arnd's patch or mine, they both fix the
problem.

-Frank

2017-04-28 21:18:43

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 2/2] of: fix unittest build without CONFIG_OF_OVERLAY

On Fri, Apr 28, 2017 at 08:40:50AM -0700, Frank Rowand wrote:
> On 04/28/17 02:44, Arnd Bergmann wrote:
> > We get a link error when the new tests are used by overlays
> > are not:
> >
> > drivers/of/built-in.o: In function `unflatten_device_tree':
> > (.init.text+0x967): undefined reference to `unittest_unflatten_overlay_base'
> >
> > This makes the #ifdef check match the symbols that lead to building
> > the unittest_unflatten_overlay_base function.
> >
> > Fixes: 81d0848fc8d2 ("of: Add unit tests for applying overlays")
> > Signed-off-by: Arnd Bergmann <[email protected]>
> > ---
> > drivers/of/of_private.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
> > index de5c604f5cc4..4ebb0149d118 100644
> > --- a/drivers/of/of_private.h
> > +++ b/drivers/of/of_private.h
> > @@ -55,7 +55,7 @@ static inline int of_property_notify(int action, struct device_node *np,
> > }
> > #endif /* CONFIG_OF_DYNAMIC */
> >
> > -#ifdef CONFIG_OF_UNITTEST
> > +#if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
> > extern void __init unittest_unflatten_overlay_base(void);
> > #else
> > static inline void unittest_unflatten_overlay_base(void) {};
> >
>
> I thought I had tested that OF_UNITTEST forced OF_OVERLAY. But
> going back and trying again, I can confirm your results that it
> does not. Thanks for catching this!
>
> Reviewed-by: Frank Rowand <[email protected]>
> Tested-by: Frank Rowand <[email protected]>

Both applied, thanks.

Rob