diff mbox

efi: Fix free_end build warning

Message ID 20141113114420.GF13350@arm.com
State New
Headers show

Commit Message

Will Deacon Nov. 13, 2014, 11:44 a.m. UTC
Hi Geoff,

On Wed, Nov 12, 2014 at 08:27:30PM +0000, Geoff Levand wrote:
> Initialize the free_end variable to zero.  Fixes build warnings
> like these:
> 
>   arch/arm64/kernel/efi.c: warning: ‘free_end’ may be used uninitialized in this function
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
> Got this with the latest arm64/for-next/core branch.  Please consider.
> 
> -Geoff 
> 
>  arch/arm64/kernel/efi.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> index 4f39a18..83fc53c 100644
> --- a/arch/arm64/kernel/efi.c
> +++ b/arch/arm64/kernel/efi.c
> @@ -239,6 +239,7 @@ static void __init free_boot_services(void)
>  	 * want to keep for UEFI.
>  	 */
>  
> +	free_end = 0;
>  	keep_end = 0;
>  	free_start = 0;

Do you have any idea how GCC arrives at this conclusion? I can't see a
path through that function where we use free_end without initialising it.

Does something like the patch below help?

Will

--->8

Comments

Geoff Levand Nov. 13, 2014, 7:42 p.m. UTC | #1
Hi Will,

On Thu, 2014-11-13 at 11:44 +0000, Will Deacon wrote:
> Do you have any idea how GCC arrives at this conclusion? I can't see a
> path through that function where we use free_end without initialising it.

I've seen it warn like this before, when it shouldn't. I guess
-Wmaybe-uninitialized makes it more conservative.

Using:

  aarch64-linux-gnu-gcc (Ubuntu/Linaro 4.8.2-13ubuntu1) 4.8.2 20140110 (prerelease) [ibm/gcc-4_8-branch merged from gcc-4_8-branch, revision 205847]

> Does something like the patch below help?

Here is the full output, for-next/core gives:

/home/geoff/projects/linaro/git/linux-kexec/arch/arm64/kernel/efi.c:281:31: warning: ‘free_end’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     total_freed += free_region(free_start, free_end);
                               ^
/home/geoff/projects/linaro/git/linux-kexec/arch/arm64/kernel/efi.c:225:28: note: ‘free_end’ was declared here
  u64 keep_end, free_start, free_end;
                            ^
Your mod gives:

/home/geoff/projects/linaro/git/linux-kexec/arch/arm64/kernel/efi.c:279:31: warning: ‘free_end’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     total_freed += free_region(free_start, free_end);
                               ^
/home/geoff/projects/linaro/git/linux-kexec/arch/arm64/kernel/efi.c:225:28: note: ‘free_end’ was declared here
  u64 keep_end, free_start, free_end;
                            ^
So about the same.

-Geoff
diff mbox

Patch

diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 95c49ebc660d..4c577b538d1c 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -271,17 +271,16 @@  static void __init free_boot_services(void)
                size = npages << PAGE_SHIFT;
 
                if (free_start) {
-                       if (paddr <= free_end)
-                               free_end = paddr + size;
-                       else {
+                       if (paddr > free_end) {
                                total_freed += free_region(free_start, free_end);
                                free_start = paddr;
-                               free_end = paddr + size;
                        }
                } else {
                        free_start = paddr;
-                       free_end = paddr + size;
                }
+
+               free_end = paddr + size;
+
                if (free_start < keep_end) {
                        free_start += PAGE_SIZE;
                        if (free_start >= free_end)