diff mbox series

[U-Boot] env: suppress a spurious warning with GCC 7.1

Message ID 1511303381-57205-1-git-send-email-philipp.tomsich@theobroma-systems.com
State Accepted
Commit fd374665c9b724bb3eb0da32db0bb7ecc5cf1337
Delegated to: Tom Rini
Headers show
Series [U-Boot] env: suppress a spurious warning with GCC 7.1 | expand

Commit Message

Philipp Tomsich Nov. 21, 2017, 10:29 p.m. UTC
GCC 7.1 seems to be smart enough to track val through the various
static inline functions, but not smart enough to see that val will
always be initialised when no error is returned.  This triggers
the following warning:
  env/mmc.c: In function 'mmc_get_env_addr':
  env/mmc.c:121:12: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]

To make it easier for compiler to understand what is going on, let's
initialise val.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
---

 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Nov. 24, 2017, 10:36 p.m. UTC | #1
On 21 November 2017 at 15:29, Philipp Tomsich
<philipp.tomsich@theobroma-systems.com> wrote:
> GCC 7.1 seems to be smart enough to track val through the various
> static inline functions, but not smart enough to see that val will
> always be initialised when no error is returned.  This triggers
> the following warning:
>   env/mmc.c: In function 'mmc_get_env_addr':
>   env/mmc.c:121:12: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
>
> To make it easier for compiler to understand what is going on, let's
> initialise val.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
>
>  env/mmc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Nov. 30, 2017, 3:36 p.m. UTC | #2
On Tue, Nov 21, 2017 at 11:29:40PM +0100, Philipp Tomsich wrote:

> GCC 7.1 seems to be smart enough to track val through the various
> static inline functions, but not smart enough to see that val will
> always be initialised when no error is returned.  This triggers
> the following warning:
>   env/mmc.c: In function 'mmc_get_env_addr':
>   env/mmc.c:121:12: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> To make it easier for compiler to understand what is going on, let's
> initialise val.
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/env/mmc.c b/env/mmc.c
index 3343f9e..ed7bcf1 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -73,7 +73,7 @@  static inline s64 mmc_offset(int copy)
 		.partition = "u-boot,mmc-env-partition",
 		.offset = "u-boot,mmc-env-offset",
 	};
-	s64 val, defvalue;
+	s64 val = 0, defvalue;
 	const char *propname;
 	const char *str;
 	int err;