Skip to contentSkip to conversation

efi: Fix free_end build warning

PATCH New Geoff Levand 3 participants 6 messages Nov 12, 2014 – Nov 14, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: Fix free_end build warning

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

---
Got this with the latest arm64/for-next/core branch. Please consider.

-Geoff

 arch/arm64/kernel/efi.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/efi.c +1 -0
index 4f39a18..83fc53c 100644
@@ -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;
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 efi: Fix free_end build warning

Hi Geoff,

Quoted 19 lines · Geoff Levand

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

---
Got this with the latest arm64/for-next/core branch. Please consider.

(quoted diff) +0 -1
-Geoff 
 
 arch/arm64/kernel/efi.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/efi.c +0 -0
index 4f39a18..83fc53c 100644

arch/arm64/kernel/efi.c static void __init free_boot_services(void) · line 244

Quoted 6 lines
arch/arm64/kernel/efi.c +1 -0
@@ -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

arch/arm64/kernel/efi.c +4 -5
index 95c49ebc660d..4c577b538d1c 100644
@@ -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)
#2 lore raw

PATCH 1/1 efi: Fix free_end build warning

Hi Will,

Quoted 2 lines · Will Deacon

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]

Quoted 1 line

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

#3 lore raw

PATCH 1/1 efi: Fix free_end build warning

In reply to Geoff Levand

[Adding original authors]

Quoted 19 lines · Geoff Levand

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

---
Got this with the latest arm64/for-next/core branch. Please consider.

(quoted diff) +0 -1
-Geoff 
 
 arch/arm64/kernel/efi.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/efi.c +0 -0
index 4f39a18..83fc53c 100644

arch/arm64/kernel/efi.c static void __init free_boot_services(void) · line 244

Quoted 6 lines
arch/arm64/kernel/efi.c +1 -0
@@ -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;

Whilst I can't see how free_end gets used uninitialized in this function, the code is really hard to read and I'd like to get an Ack from one of the people on CC before merging this, just in case GCC is actually telling us something useful for a change.

Will

#4 lore raw

PATCH 1/1 efi: Fix free_end build warning

Quoted 25 lines · Will Deacon

[Adding original authors]

Quoted 22 lines · Geoff Levand

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

---
Got this with the latest arm64/for-next/core branch. Please consider.

(quoted diff) +0 -1
-Geoff
 
 arch/arm64/kernel/efi.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/efi.c +0 -0
index 4f39a18..83fc53c 100644
@@ -239,6 +239,7 @@ static void __init free_boot_services(void)
       * want to keep for UEFI.
       */
 
Quoted 9 lines

arch/arm64/kernel/efi.c static void __init free_boot_services(void) · line 244

Quoted 3 lines
arch/arm64/kernel/efi.c +1 -0
+     free_end = 0;
      keep_end = 0;
      free_start = 0;

Whilst I can't see how free_end gets used uninitialized in this function, the code is really hard to read and I'd like to get an Ack from one of the people on CC before merging this, just in case GCC is actually telling us something useful for a change.

We are planning to remove this code entirely in the 3.20 timeframe. Freeing boot services will not be necessary any longer once we stop reserving it in the first place, and I agree that the function is hard to read. Also, it depends on the UEFI memory map being sorted, which is not mandated by the spec so we can't actually rely on it. (Even if it usually is the case)

So I don't object to this patch, if the warning is bothering people, but perhaps we can just wait for the warning to go away once the new stuff lands.

Signature · 1 line
Ard.
#5 lore raw

PATCH 1/1 efi: Fix free_end build warning

Quoted 43 lines · Ard Biesheuvel
Quoted 25 lines · Will Deacon

[Adding original authors]

Quoted 22 lines · Geoff Levand

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

---
Got this with the latest arm64/for-next/core branch. Please consider.

(quoted diff) +0 -1
-Geoff
 
 arch/arm64/kernel/efi.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/efi.c +0 -0
index 4f39a18..83fc53c 100644
@@ -239,6 +239,7 @@ static void __init free_boot_services(void)
       * want to keep for UEFI.
       */
 
Quoted 9 lines

arch/arm64/kernel/efi.c static void __init free_boot_services(void) · line 244

Quoted 3 lines
arch/arm64/kernel/efi.c +1 -0
+     free_end = 0;
      keep_end = 0;
      free_start = 0;

Whilst I can't see how free_end gets used uninitialized in this function, the code is really hard to read and I'd like to get an Ack from one of the people on CC before merging this, just in case GCC is actually telling us something useful for a change.

We are planning to remove this code entirely in the 3.20 timeframe. Freeing boot services will not be necessary any longer once we stop reserving it in the first place, and I agree that the function is hard to read. Also, it depends on the UEFI memory map being sorted, which is not mandated by the spec so we can't actually rely on it. (Even if it usually is the case)

Quoted 3 lines

So I don't object to this patch, if the warning is bothering people, but perhaps we can just wait for the warning to go away once the new stuff lands.

Ok, thanks Ard. I think I'll leave it alone for now, then.

Will