Skip to contentSkip to conversation

compile time warnings

PATCH In review Ingo Brueckl 6 participants 14 messages Jan 1, 2009 – Jan 2, 2009

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

Maybe somebody noticed already, with kernel 2.6.28 and gcc 4.3.2 there are a few compile time warnings:

arch/x86/kernel/setup.c:742: warning: 'dmi_low_memory_corruption' defined but not used

arch/x86/mm/init_32.c: In function 'pagetable_init':
arch/x86/mm/init_32.c:515: warning: unused variable 'pgd_base'

drivers/acpi/tables/tbfadt.c: In function 'acpi_tb_create_local_fadt':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

drivers/usb/core/hcd.c: In function 'usb_hcd_poll_rh_status':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

WARNING: modpost: Found 1 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'

#1 lore raw
Quoted 3 lines · Ingo Brueckl

Maybe somebody noticed already, with kernel 2.6.28 and gcc 4.3.2 there are a few compile time warnings:

I've looked at these with the kernel from git as of today. I've only read the code, not build it.

Quoted 2 lines

arch/x86/kernel/setup.c:742: warning: 'dmi_low_memory_corruption' defined but not used

I see dmi_low_memory_corruption() as well as usage of it both inside #ifdef CONFIG_X86_RESERVE_LOW_64K - looks fine to me:

#ifdef CONFIG_X86_RESERVE_LOW_64K
static int __init dmi_low_memory_corruption(const struct dmi_system_id *d) {
...
static struct dmi_system_id __initdata bad_bios_dmi_table[] = { #ifdef CONFIG_X86_RESERVE_LOW_64K
{
.callback = dmi_low_memory_corruption,
...

Quoted 3 lines

arch/x86/mm/init_32.c: In function 'pagetable_init':
arch/x86/mm/init_32.c:515: warning: unused variable 'pgd_base'

I see this :

static void __init pagetable_init(void)

{
        pgd_t *pgd_base = swapper_pg_dir;

        permanent_kmaps_init(pgd_base);
}

pgd_base is very much used...

Quoted 6 lines

drivers/acpi/tables/tbfadt.c: In function 'acpi_tb_create_local_fadt':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

drivers/usb/core/hcd.c: In function 'usb_hcd_poll_rh_status':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

Not sure about these.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#2 lore raw

2009/1/1 Jesper Juhl <[email protected]>:

Quoted 1 line · Ingo Brueckl

[snip]

Hi,

Quoted 1 line

pgd_base is very much used...

It's probably something to do with:

# define permanent_kmaps_init(pgd_base)         do { } while (0)

Which is within the #else part of #if CONFIG_HIGHMEM. So, if CONFIG_HIGHMEM is not set, permanent_kmaps_init gets wiped out, and therefore that warning will be issued.

Perhaps changing that to an empty inline would remove the warning?

Signature · 2 lines
Tom Spink
G. Gordon Liddy  - "Obviously crime pays, or there'd be no crime."
#3 lore raw
Quoted 10 lines · Tom Spink

2009/1/1 Jesper Juhl <[email protected]>:

Quoted 1 line · Ingo Brueckl

[snip]

Hi,

Quoted 1 line

pgd_base is very much used...

It's probably something to do with:

Quoted 8 lines
# define permanent_kmaps_init(pgd_base)         do { } while (0)

Which is within the #else part of #if CONFIG_HIGHMEM. So, if CONFIG_HIGHMEM is not set, permanent_kmaps_init gets wiped out, and therefore that warning will be issued.

Perhaps changing that to an empty inline would remove the warning?

If it can be an inline, it should be, otherwise:

# define permanent_kmaps_init(pgd_base) do { (void)(pgd_base) } while (0)

would do the trick.

Harvey

#4 lore raw
In reply to Tom Spink
Quoted 10 lines · Tom Spink

2009/1/1 Jesper Juhl <[email protected]>:

Quoted 1 line · Ingo Brueckl

[snip]

Hi,

Quoted 1 line

pgd_base is very much used...

It's probably something to do with:

Quoted 8 lines
# define permanent_kmaps_init(pgd_base)         do { } while (0)

Which is within the #else part of #if CONFIG_HIGHMEM. So, if CONFIG_HIGHMEM is not set, permanent_kmaps_init gets wiped out, and therefore that warning will be issued.

Perhaps changing that to an empty inline would remove the warning?

Yeah, I noticed that as well after sending the mail. Another way to silence the warning (which I think is nicer) would be something like this;

Silence 'unused variable' warning in arch/x86/mm/init_32.c::pagetable_init

---

arch/x86/mm/init_32.c +1 -3
index 8655b5b..0affa8e 100644
@@ -511,9 +511,7 @@ static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base)
 
 static void __init pagetable_init(void)
 {
-	pgd_t *pgd_base = swapper_pg_dir;
-
-	permanent_kmaps_init(pgd_base);
+	permanent_kmaps_init((pgd_t *)swapper_pg_dir);
 }
 
 #ifdef CONFIG_ACPI_SLEEP
Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#12 lore raw
In reply to Ingo Brueckl

What we have so far:

arch/x86/kernel/setup.c:742: warning: 'dmi_low_memory_corruption'

is already fixed in the git tree.

arch/x86/mm/init_32.c:515: warning: unused variable 'pgd_base'

could be fixed with Jespers patch (which I like best).

WARNING: modpost: Found 1 section mismatch(es).

which is (with CONFIG_DEBUG_SECTION_MISMATCH=y):

WARNING: vmlinux.o(.cpuinit.data+0x0): Section mismatch in reference from the variable initial_code to the function .init.text:i386_start_kernel() The variable __cpuinitdata initial_code references a function __init i386_start_kernel(). If i386_start_kernel is only used by initial_code then annotate i386_start_kernel with a matching annotation.

was already noticed some time ago by [email protected], but is still unfixed.

Here is what [email protected] suggested:

arch/x86/kernel/head_32.S +1 -0
@@ -600,6 +600,7 @@ ignore_int:
 
 .section .cpuinit.data,"wa"
 .align 4
+__REFDATA
 ENTRY(initial_code)
 	.long i386_start_kernel
 

The remaining

/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

is very strange and a mystery to me. (There were already reports on that issue which seem to point to a gcc bug.)

#5 lore raw
In reply to Jesper Juhl
Quoted 35 lines · Jesper Juhl
Quoted 10 lines · Tom Spink

2009/1/1 Jesper Juhl <[email protected]>:

Quoted 1 line · Ingo Brueckl

[snip]

Hi,

Quoted 1 line

pgd_base is very much used...

It's probably something to do with:

Quoted 8 lines
# define permanent_kmaps_init(pgd_base)         do { } while (0)

Which is within the #else part of #if CONFIG_HIGHMEM. So, if CONFIG_HIGHMEM is not set, permanent_kmaps_init gets wiped out, and therefore that warning will be issued.

Perhaps changing that to an empty inline would remove the warning?

Yeah, I noticed that as well after sending the mail. Another way to silence the warning (which I think is nicer) would be something like this;

Silence 'unused variable' warning in arch/x86/mm/init_32.c::pagetable_init

---

arch/x86/mm/init_32.c +0 -0
index 8655b5b..0affa8e 100644

arch/x86/mm/init_32.c static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base) · line 515

Quoted 8 lines
arch/x86/mm/init_32.c +1 -3
@@ -511,9 +511,7 @@ static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base)
 
 static void __init pagetable_init(void)
 {
-	pgd_t *pgd_base = swapper_pg_dir;
-
-	permanent_kmaps_init(pgd_base);
+	permanent_kmaps_init((pgd_t *)swapper_pg_dir);
 }

no, this only works around the warning by 'silencing' it (it also includes an ugly type cast) - instead of fixing the core problem.

The core problem is that permanent_kmaps_init() is a CPP macro in the !HIGHMEM case - so the right fix would be to convert that to a proper C inline function. (same for set_highmem_pages_init() while at it)

Would you mind to send a patch for that that we could push to Linus?

<soapbox>

The highest quality fixes that are motivated by compiler warnings are the ones that do not actually 'fix a warning', but instead improve/reshape some code so that as a side-effect the warning goes away.

If you ever see a patch that 'silences a warning', it usually shows that the deeper problem has not been fully understood. (Except of course if the warning shows a genuine bug in the code - but in that case we fix the bug and not the warning - the warning was just the canary to it.)

</soapbox>

Ingo

#6 lore raw

PATCH 1/1 compile time warnings

Quoted 1 line · Ingo Molnar

Would you mind to send a patch for that that we could push to Linus?

Do you mean something like:

fix compiler warning in arch/x86/mm/init_32.c

arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c.orig +7 -2
@@ -436,8 +436,13 @@ static void __init set_highmem_pages_ini
 #endif /* !CONFIG_NUMA */
 
 #else
-# define permanent_kmaps_init(pgd_base)		do { } while (0)
-# define set_highmem_pages_init()	do { } while (0)
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+	(void) pgd_base;
+}
+static inline void set_highmem_pages_init(void)
+{
+}
 #endif /* CONFIG_HIGHMEM */
 
 void __init native_pagetable_setup_start(pgd_t *base)
#7 lore raw
Quoted 7 lines · Ingo Brueckl
Quoted 1 line · Ingo Molnar

Would you mind to send a patch for that that we could push to Linus?

Do you mean something like:

fix compiler warning in arch/x86/mm/init_32.c

yes, with a small nit:

arch/x86/mm/init_32.c static void __init set_highmem_pages_ini · line 441

Quoted 4 lines
arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c.orig +3 -0
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+	(void) pgd_base;

there's no need for this line - this is not a macro, so the function parameter does not have to be 'used'.

Ingo

#8 lore raw

PATCH 1/1 compile time warnings

Quoted 8 lines · Ingo Molnar

yes, with a small nit:

Review

Quoted 4 lines
(quoted diff) +3 -0
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+     (void) pgd_base;

there's no need for this line - this is not a macro, so the function parameter does not have to be 'used'.

I live and learn.

fix compiler warning in arch/x86/mm/init_32.c

arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c.orig +6 -2
@@ -436,8 +436,12 @@ static void __init set_highmem_pages_ini
 #endif /* !CONFIG_NUMA */
 
 #else
-# define permanent_kmaps_init(pgd_base)		do { } while (0)
-# define set_highmem_pages_init()	do { } while (0)
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+}
+static inline void set_highmem_pages_init(void)
+{
+}
 #endif /* CONFIG_HIGHMEM */
 
 void __init native_pagetable_setup_start(pgd_t *base)
Applied
#9 lore raw
Quoted 11 lines · Ingo Brueckl
Quoted 8 lines · Ingo Molnar

yes, with a small nit:

Review

Quoted 4 lines
(quoted diff) +3 -0
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+     (void) pgd_base;

there's no need for this line - this is not a macro, so the function parameter does not have to be 'used'.

Quoted 3 lines

I live and learn.

fix compiler warning in arch/x86/mm/init_32.c

applied to tip/x86/cleanups, thanks! Find below the final form of the commit.

Ingo

---------------->

Quoted 1 line

From a9067d537615d534dcef06c0d819472e43a0d152 Mon Sep 17 00:00:00 2001

From: Ingo Brueckl <[email protected]>
Date: Fri, 2 Jan 2009 14:42:00 +0100
Subject: [PATCH] x86: convert permanent_kmaps_init() from macro to inline

Impact: cleanup

This compiler warning:

arch/x86/mm/init_32.c:515: warning: unused variable 'pgd_base'

triggers because permanent_kmaps_init() is a CPP macro in the !CONFIG_HIGHMEM case, that does not tell the compiler that the 'pgd_base' parameter is used.

Convert permanent_kmaps_init() (and set_highmem_pages_init()) to C inline functions - which gives the parameter a proper type and which gets rid of the compiler warning as well.

---
 arch/x86/mm/init_32.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/mm/init_32.c +6 -2
index 800e1d9..ad98b18 100644
@@ -434,8 +434,12 @@ static void __init set_highmem_pages_init(void)
 #endif /* !CONFIG_NUMA */
 
 #else
-# define permanent_kmaps_init(pgd_base)		do { } while (0)
-# define set_highmem_pages_init()	do { } while (0)
+static inline void permanent_kmaps_init(pgd_t *pgd_base)
+{
+}
+static inline void set_highmem_pages_init(void)
+{
+}
 #endif /* CONFIG_HIGHMEM */
 
 void __init native_pagetable_setup_start(pgd_t *base)
#10 lore raw
In reply to Ingo Molnar
Quoted 39 lines · Ingo Molnar
Quoted 36 lines · Jesper Juhl
Quoted 10 lines · Tom Spink

2009/1/1 Jesper Juhl <[email protected]>:

Quoted 1 line · Ingo Brueckl

[snip]

Hi,

Quoted 1 line

pgd_base is very much used...

It's probably something to do with:

Quoted 8 lines
# define permanent_kmaps_init(pgd_base)         do { } while (0)

Which is within the #else part of #if CONFIG_HIGHMEM. So, if CONFIG_HIGHMEM is not set, permanent_kmaps_init gets wiped out, and therefore that warning will be issued.

Perhaps changing that to an empty inline would remove the warning?

Yeah, I noticed that as well after sending the mail. Another way to silence the warning (which I think is nicer) would be something like this;

Silence 'unused variable' warning in arch/x86/mm/init_32.c::pagetable_init

---

arch/x86/mm/init_32.c +0 -0
index 8655b5b..0affa8e 100644
@@ -511,9 +511,7 @@ static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base)
 
Quoted 11 lines

arch/x86/mm/init_32.c static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base) · line 515

Quoted 7 lines
arch/x86/mm/init_32.c +1 -3
 static void __init pagetable_init(void)
 {
-	pgd_t *pgd_base = swapper_pg_dir;
-
-	permanent_kmaps_init(pgd_base);
+	permanent_kmaps_init((pgd_t *)swapper_pg_dir);
 }

no, this only works around the warning by 'silencing' it (it also includes an ugly type cast) - instead of fixing the core problem.

Hmm, true..

Quoted 6 lines

The core problem is that permanent_kmaps_init() is a CPP macro in the !HIGHMEM case - so the right fix would be to convert that to a proper C inline function. (same for set_highmem_pages_init() while at it)

Would you mind to send a patch for that that we could push to Linus?

Sure, I'll do that.

Quoted 6 lines

<soapbox>

The highest quality fixes that are motivated by compiler warnings are the ones that do not actually 'fix a warning', but instead improve/reshape some code so that as a side-effect the warning goes away.

Quoted 7 lines

If you ever see a patch that 'silences a warning', it usually shows that the deeper problem has not been fully understood. (Except of course if the warning shows a genuine bug in the code - but in that case we fix the bug and not the warning - the warning was just the canary to it.)

</soapbox>

Well said.

Quoted 2 lines

Ingo

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#11 lore raw
Quoted 2 lines · Jesper Juhl
Quoted 1 line · Ingo Molnar

...

Quoted 4 lines
Quoted 2 lines

Would you mind to send a patch for that that we could push to Linus?

Sure, I'll do that.

I see that Mr. Brueckl beat me to it...

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#13 lore raw
In reply to Ingo Brueckl
Quoted 4 lines · Ingo Brueckl

Maybe somebody noticed already, with kernel 2.6.28 and gcc 4.3.2 there are a
few compile time warnings:
drivers/acpi/tables/tbfadt.c: In function 'acpi_tb_create_local_fadt':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

I noticed this as well. This one looks like the compiler's getting a bit confused.

	ACPI_MEMCPY(&acpi_gbl_FADT, table,
		    ACPI_MIN(length, sizeof(struct acpi_table_fadt)));

and somehow that falls into __constant_memcpy because somehow __builtin_constant_p() on the length parameter returns true. Huh? It's a non-static function where length is passed in, and ACPI_MIN is a simple (((a)<(b))?(a):(b)) expression. How can it think that's a compile time constant I don't know. Maybe it's not and just generating warnings from the code path it's seeing but not using?

The cause of the complaint might be the fact that the memcpy may appear to read past the end of the "table" structure which points to struct acpi_table_header. Presumably that memory is bigger than the actual struct acpi_table_header though. The text of the warning itself is bizarre though, as there is no array style access happening, and I don't see how the compiler can know what the actual bounds of the "array" are.

Quoted 3 lines

drivers/usb/core/hcd.c: In function 'usb_hcd_poll_rh_status':
/usr/src/linux/arch/x86/include/asm/string_32.h:75: warning: array subscript is above array bounds

This one makes a little more sense. This is presumably:

			memcpy(urb->transfer_buffer, buffer, length);

where transfer_buffer is a void*, buffer is char[4] and length comes from hcd->driver->hub_status_data(hcd, buffer) which I assume fills in the buffer. It's true the memcpy could read past the end of the buffer array, but only if the hub_status_data could fill in and return a length greater than 4, which it hopefully can't..