Skip to contentSkip to conversation

sparc: us3_cpufreq.c: fix warnings/errors

PATCH In review Alexander Beregalov 3 participants 9 messages Dec 20, 2009 – Dec 23, 2009 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sparc: us3_cpufreq.c: fix warnings/errors

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

---
 arch/sparc/kernel/us3_cpufreq.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/kernel/us3_cpufreq.c +2 -2
index 365b646..7eb12fc 100644
@@ -57,7 +57,7 @@ static void write_safari_cfg(unsigned long val)
 static unsigned long get_current_freq(unsigned int cpu, unsigned long safari_cfg)
 {
 	unsigned long clock_tick = sparc64_get_clock_tick(cpu) / 1000;
-	unsigned long ret;
+	unsigned long ret = 0;
 
 	switch (safari_cfg & SAFARI_CFG_DIV_MASK) {
 	case SAFARI_CFG_DIV_1:
@@ -98,7 +98,7 @@ static unsigned int us3_freq_get(unsigned int cpu)
 
 static void us3_set_cpu_divider_index(unsigned int cpu, unsigned int index)
 {
-	unsigned long new_bits, new_freq, reg;
+	unsigned long new_bits = 0, new_freq, reg;
 	cpumask_t cpus_allowed;
 	struct cpufreq_freqs freqs;
 
Signature · 1 line
1.6.6.rc3
maintainer
#1 lore raw

From: Alexander Beregalov <[email protected]>
Date: Sun, 20 Dec 2009 15:16:35 +0300

Quoted 5 lines

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

The default switch case is BUG(), therefore the end of the function is unreachable.

What changed recently to cause this to start generating a warning, it never did before?

#2 lore raw
In reply to Alexander Beregalov
Quoted 3 lines · Alexander Beregalov

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

What config produces these warnings?
Do you have CONFIG_BUG_VERBOSE set?

Also what gcc versio?

Sam

#3 lore raw
In reply to Alexander Beregalov

2009/12/21 Sam Ravnborg <[email protected]>:

Quoted 10 lines · Alexander Beregalov
Quoted 3 lines

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

What config produces these warnings?
Do you have CONFIG_BUG_VERBOSE set?

Also what gcc versio?

Hi

I do not know what has changed.
I have not tried these options before.
I tested randconfig builds.
Config is attached.

gcc is 4.3.4

sparc64-unknown-linux-gnu-gcc -Wp,-MD,arch/sparc/kernel/.us3_cpufreq.o.d -nostdinc -isystem /usr/lib/gcc/sparc64-unknown-linux-gnu/4.3.4/include -I/home/alexb/src/linux-2.6/arch/sparc/include -Iinclude -include include/generated/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare -Wa,--undeclared-regs -mtune=ultrasparc3 -pg -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -Werror -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(us3_cpufreq)" -D"KBUILD_MODNAME=KBUILD_STR(us3_cpufreq)" -D"DEBUG_HASH=11" -D"DEBUG_HASH2=39" -c -o arch/sparc/kernel/.tmp_us3_cpufreq.o arch/sparc/kernel/us3_cpufreq.c
cc1: warnings being treated as errors arch/sparc/kernel/us3_cpufreq.c: In function 'get_current_freq':
arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c: In function 'us3_set_cpu_divider_index':
arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function
make[1]: *** [arch/sparc/kernel/us3_cpufreq.o] Error 1

#4 lore raw
In reply to Alexander Beregalov

2009/12/21 Alexander Beregalov <[email protected]>:

Quoted 11 lines

2009/12/21 Sam Ravnborg <[email protected]>:

Quoted 10 lines · Alexander Beregalov
Quoted 3 lines

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

What config produces these warnings?
Do you have CONFIG_BUG_VERBOSE set?

Also what gcc versio?

Ah, this is it.

# CONFIG_BUG is not set

Is it sane config ?

Quoted 36 lines

Hi

I do not know what has changed.
I have not tried these options before.
I tested randconfig builds.
Config is attached.

gcc is 4.3.4

sparc64-unknown-linux-gnu-gcc -Wp,-MD,arch/sparc/kernel/.us3_cpufreq.o.d  -nostdinc -isystem /usr/lib/gcc/sparc64-unknown-linux-gnu/4.3.4/include -I/home/alexb/src/linux-2.6/arch/sparc/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -Wall -Wundef

(quoted diff) +0 -11
-Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
-Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -Os -m64 -pipe -mno-fpu
-mcpu=ultrasparc -mcmodel=medlow -ffixed-g4 -ffixed-g5 -fcall-used-g7
-Wno-sign-compare -Wa,--undeclared-regs -mtune=ultrasparc3 -pg
-fno-stack-protector -fno-omit-frame-pointer
-fno-optimize-sibling-calls -Wdeclaration-after-statement
-Wno-pointer-sign -fno-strict-overflow -Werror -D"KBUILD_STR(s)=#s"
-D"KBUILD_BASENAME=KBUILD_STR(us3_cpufreq)"
-D"KBUILD_MODNAME=KBUILD_STR(us3_cpufreq)" -D"DEBUG_HASH"
-D"DEBUG_HASH29" -c -o arch/sparc/kernel/.tmp_us3_cpufreq.o

arch/sparc/kernel/us3_cpufreq.c
cc1: warnings being treated as errors arch/sparc/kernel/us3_cpufreq.c: In function 'get_current_freq':
arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c: In function 'us3_set_cpu_divider_index':
arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function
make[1]: *** [arch/sparc/kernel/us3_cpufreq.o] Error 1

#5 lore raw
In reply to Alexander Beregalov
Quoted 10 lines · Alexander Beregalov

2009/12/21 Alexander Beregalov <[email protected]>:

Quoted 9 lines

2009/12/21 Sam Ravnborg <[email protected]>:

Quoted 8 lines · Alexander Beregalov
Quoted 3 lines

Fix warnings which become build errors since -Werror is used. arch/sparc/kernel/us3_cpufreq.c:60: error: 'ret' may be used uninitialized in this function arch/sparc/kernel/us3_cpufreq.c:101: error: 'new_bits' may be used uninitialized in this function

What config produces these warnings?
Do you have CONFIG_BUG_VERBOSE set?

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Also what gcc versio?

Ah, this is it.

# CONFIG_BUG is not set

Is it sane config ?

Only embedded size constrained configs would
consider this.

The reason for the warning is this snippet from
include/asm-generic/bug.h:

#define BUG() do {} while(0)

The above only comes into effect when CONFIG_BUG is not set.

I dunno what the best fix is here.
Embedded or not - I cannot see why we should continue execution after a BUG().
Code will assume we panicked and following code not to be executed.

As the comment says:
"Don't use BUG() or BUG_ON() unless there's really no way out;"

I would have expected to see something like this:
#define BUG() do {} while(1)

A never ending loop so the watchdog on embedded systems could force a reboot. IMO more safe than continue and do random curruption of stuff all over.

David Howells added the do {} while(0) - so cc: on this mail.

Sam

maintainer
#6 lore raw
In reply to Alexander Beregalov

From: Sam Ravnborg <[email protected]>
Date: Mon, 21 Dec 2009 20:59:21 +0100

Quoted 5 lines

As the comment says:
"Don't use BUG() or BUG_ON() unless there's really no way out;"

I would have expected to see something like this:
#define BUG() do {} while(1)

Maybe we can use "unreachable()" here.

#7 lore raw
In reply to Alexander Beregalov
Quoted 10 lines · David Miller

From: Sam Ravnborg <[email protected]>
Date: Mon, 21 Dec 2009 20:59:21 +0100

Quoted 5 lines

As the comment says:
"Don't use BUG() or BUG_ON() unless there's really no way out;"

I would have expected to see something like this:
#define BUG() do {} while(1)

Maybe we can use "unreachable()" here.

Makes sense.

Alexander - could you please try to add an
unreachable() call in in bug.h and if it
kills the warnings as expected then send
a patch to Arnd including a proper
changelog describing why this was need.

I copied Arnd on this mail albeit he may miss some context... In short - Alexandar posted a few patches to get rid of a set of warnings on sparc.
The root cause of the warnings was the definition of BUG() when CONFIG_BUG is not set.

Sam

#8 lore raw
In reply to Alexander Beregalov

2009/12/21 Sam Ravnborg <[email protected]>:

Quoted 10 lines · David Miller
Quoted 9 lines

From: Sam Ravnborg <[email protected]>
Date: Mon, 21 Dec 2009 20:59:21 +0100

Quoted 5 lines

As the comment says:
"Don't use BUG() or BUG_ON() unless there's really no way out;"

I would have expected to see something like this:
#define BUG() do {} while(1)

Quoted 8 lines
Quoted 1 line

Maybe we can use "unreachable()" here.

Makes sense.

Alexander - could you please try to add an unreachable() call in in bug.h and if it kills the warnings as expected then send a patch to Arnd including a proper changelog describing why this was need.

It fixes the problem, thanks!