All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
@ 2013-08-21 10:47 ` Markos Chandras
  0 siblings, 0 replies; 8+ messages in thread
From: Markos Chandras @ 2013-08-21 10:47 UTC (permalink / raw)
  To: linux-mips; +Cc: Markos Chandras

Fixes the following build error:
arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
In file included from arch/mips/ath79/common.c:20:0:
arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
arch/mips/include/asm/mach-ath79/ath79.h:139:20:
error: 'reg' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
arch/mips/ath79/common.c:90:6: note: 'reg' was declared here

Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
---
Changes since v1:
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00126.html
- Remove BUG(). panic() is enough.
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00133.html
- Change panic() message to be more accurate.
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00164.html
---
 arch/mips/ath79/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/ath79/common.c b/arch/mips/ath79/common.c
index eb3966c..6d7a9d4 100644
--- a/arch/mips/ath79/common.c
+++ b/arch/mips/ath79/common.c
@@ -75,7 +75,7 @@ void ath79_device_reset_set(u32 mask)
 	else if (soc_is_qca955x())
 		reg = QCA955X_RESET_REG_RESET_MODULE;
 	else
-		BUG();
+		panic("Reset register not defined for this SOC");
 
 	spin_lock_irqsave(&ath79_device_reset_lock, flags);
 	t = ath79_reset_rr(reg);
@@ -103,7 +103,7 @@ void ath79_device_reset_clear(u32 mask)
 	else if (soc_is_qca955x())
 		reg = QCA955X_RESET_REG_RESET_MODULE;
 	else
-		BUG();
+		panic("Reset register not defined for this SOC");
 
 	spin_lock_irqsave(&ath79_device_reset_lock, flags);
 	t = ath79_reset_rr(reg);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
@ 2013-08-21 10:47 ` Markos Chandras
  0 siblings, 0 replies; 8+ messages in thread
From: Markos Chandras @ 2013-08-21 10:47 UTC (permalink / raw)
  To: linux-mips; +Cc: Markos Chandras

Fixes the following build error:
arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
In file included from arch/mips/ath79/common.c:20:0:
arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
arch/mips/include/asm/mach-ath79/ath79.h:139:20:
error: 'reg' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
arch/mips/ath79/common.c:90:6: note: 'reg' was declared here

Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
---
Changes since v1:
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00126.html
- Remove BUG(). panic() is enough.
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00133.html
- Change panic() message to be more accurate.
http://www.linux-mips.org/archives/linux-mips/2013-08/msg00164.html
---
 arch/mips/ath79/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/ath79/common.c b/arch/mips/ath79/common.c
index eb3966c..6d7a9d4 100644
--- a/arch/mips/ath79/common.c
+++ b/arch/mips/ath79/common.c
@@ -75,7 +75,7 @@ void ath79_device_reset_set(u32 mask)
 	else if (soc_is_qca955x())
 		reg = QCA955X_RESET_REG_RESET_MODULE;
 	else
-		BUG();
+		panic("Reset register not defined for this SOC");
 
 	spin_lock_irqsave(&ath79_device_reset_lock, flags);
 	t = ath79_reset_rr(reg);
@@ -103,7 +103,7 @@ void ath79_device_reset_clear(u32 mask)
 	else if (soc_is_qca955x())
 		reg = QCA955X_RESET_REG_RESET_MODULE;
 	else
-		BUG();
+		panic("Reset register not defined for this SOC");
 
 	spin_lock_irqsave(&ath79_device_reset_lock, flags);
 	t = ath79_reset_rr(reg);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
  2013-08-21 10:47 ` Markos Chandras
  (?)
@ 2013-08-21 16:40 ` Gabor Juhos
  -1 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2013-08-21 16:40 UTC (permalink / raw)
  To: Markos Chandras; +Cc: linux-mips

2013.08.21. 12:47 keltezéssel, Markos Chandras írta:
> Fixes the following build error:
> arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
> arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
> In file included from arch/mips/ath79/common.c:20:0:
> arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
> arch/mips/include/asm/mach-ath79/ath79.h:139:20:
> error: 'reg' may be used uninitialized in this function
> [-Werror=maybe-uninitialized]
> arch/mips/ath79/common.c:90:6: note: 'reg' was declared here
> 
> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>

Acked-by: Gabor Juhos <juhosg@openwrt.org>

Thanks!

-Gabor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
  2013-08-21 10:47 ` Markos Chandras
  (?)
  (?)
@ 2013-09-03 13:38 ` Ralf Baechle
  2013-09-03 14:03     ` Markos Chandras
  -1 siblings, 1 reply; 8+ messages in thread
From: Ralf Baechle @ 2013-09-03 13:38 UTC (permalink / raw)
  To: Markos Chandras; +Cc: linux-mips

On Wed, Aug 21, 2013 at 11:47:22AM +0100, Markos Chandras wrote:

> Fixes the following build error:
> arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
> arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
> In file included from arch/mips/ath79/common.c:20:0:
> arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
> arch/mips/include/asm/mach-ath79/ath79.h:139:20:
> error: 'reg' may be used uninitialized in this function
> [-Werror=maybe-uninitialized]
> arch/mips/ath79/common.c:90:6: note: 'reg' was declared here
> 
> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
> ---
> Changes since v1:
> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00126.html
> - Remove BUG(). panic() is enough.
> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00133.html
> - Change panic() message to be more accurate.
> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00164.html
> ---
>  arch/mips/ath79/common.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/mips/ath79/common.c b/arch/mips/ath79/common.c
> index eb3966c..6d7a9d4 100644
> --- a/arch/mips/ath79/common.c
> +++ b/arch/mips/ath79/common.c
> @@ -75,7 +75,7 @@ void ath79_device_reset_set(u32 mask)
>  	else if (soc_is_qca955x())
>  		reg = QCA955X_RESET_REG_RESET_MODULE;
>  	else
> -		BUG();
> +		panic("Reset register not defined for this SOC");
>  
>  	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>  	t = ath79_reset_rr(reg);
> @@ -103,7 +103,7 @@ void ath79_device_reset_clear(u32 mask)
>  	else if (soc_is_qca955x())
>  		reg = QCA955X_RESET_REG_RESET_MODULE;
>  	else
> -		BUG();
> +		panic("Reset register not defined for this SOC");
>  
>  	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>  	t = ath79_reset_rr(reg);

Looks more like the implementation of BUG() is wrong and gcc doesn't
notice that BUG() won't return.

Was this triggered by CONFIG_BUG=n?

  Ralf

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
@ 2013-09-03 14:03     ` Markos Chandras
  0 siblings, 0 replies; 8+ messages in thread
From: Markos Chandras @ 2013-09-03 14:03 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On 09/03/13 14:38, Ralf Baechle wrote:
> On Wed, Aug 21, 2013 at 11:47:22AM +0100, Markos Chandras wrote:
>
>> Fixes the following build error:
>> arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
>> uninitialized in this function [-Werror=maybe-uninitialized]
>> arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
>> In file included from arch/mips/ath79/common.c:20:0:
>> arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
>> arch/mips/include/asm/mach-ath79/ath79.h:139:20:
>> error: 'reg' may be used uninitialized in this function
>> [-Werror=maybe-uninitialized]
>> arch/mips/ath79/common.c:90:6: note: 'reg' was declared here
>>
>> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>> ---
>> Changes since v1:
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00126.html
>> - Remove BUG(). panic() is enough.
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00133.html
>> - Change panic() message to be more accurate.
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00164.html
>> ---
>>   arch/mips/ath79/common.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/mips/ath79/common.c b/arch/mips/ath79/common.c
>> index eb3966c..6d7a9d4 100644
>> --- a/arch/mips/ath79/common.c
>> +++ b/arch/mips/ath79/common.c
>> @@ -75,7 +75,7 @@ void ath79_device_reset_set(u32 mask)
>>   	else if (soc_is_qca955x())
>>   		reg = QCA955X_RESET_REG_RESET_MODULE;
>>   	else
>> -		BUG();
>> +		panic("Reset register not defined for this SOC");
>>
>>   	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>>   	t = ath79_reset_rr(reg);
>> @@ -103,7 +103,7 @@ void ath79_device_reset_clear(u32 mask)
>>   	else if (soc_is_qca955x())
>>   		reg = QCA955X_RESET_REG_RESET_MODULE;
>>   	else
>> -		BUG();
>> +		panic("Reset register not defined for this SOC");
>>
>>   	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>>   	t = ath79_reset_rr(reg);
>
> Looks more like the implementation of BUG() is wrong and gcc doesn't
> notice that BUG() won't return.
>
> Was this triggered by CONFIG_BUG=n?
>
>    Ralf
>

Hi Ralf,

Yes it was triggered by CONFIG_BUG=n

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
@ 2013-09-03 14:03     ` Markos Chandras
  0 siblings, 0 replies; 8+ messages in thread
From: Markos Chandras @ 2013-09-03 14:03 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On 09/03/13 14:38, Ralf Baechle wrote:
> On Wed, Aug 21, 2013 at 11:47:22AM +0100, Markos Chandras wrote:
>
>> Fixes the following build error:
>> arch/mips/include/asm/mach-ath79/ath79.h:139:20: error: 'reg' may be used
>> uninitialized in this function [-Werror=maybe-uninitialized]
>> arch/mips/ath79/common.c:62:6: note: 'reg' was declared here
>> In file included from arch/mips/ath79/common.c:20:0:
>> arch/mips/ath79/common.c: In function 'ath79_device_reset_clear':
>> arch/mips/include/asm/mach-ath79/ath79.h:139:20:
>> error: 'reg' may be used uninitialized in this function
>> [-Werror=maybe-uninitialized]
>> arch/mips/ath79/common.c:90:6: note: 'reg' was declared here
>>
>> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>> ---
>> Changes since v1:
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00126.html
>> - Remove BUG(). panic() is enough.
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00133.html
>> - Change panic() message to be more accurate.
>> http://www.linux-mips.org/archives/linux-mips/2013-08/msg00164.html
>> ---
>>   arch/mips/ath79/common.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/mips/ath79/common.c b/arch/mips/ath79/common.c
>> index eb3966c..6d7a9d4 100644
>> --- a/arch/mips/ath79/common.c
>> +++ b/arch/mips/ath79/common.c
>> @@ -75,7 +75,7 @@ void ath79_device_reset_set(u32 mask)
>>   	else if (soc_is_qca955x())
>>   		reg = QCA955X_RESET_REG_RESET_MODULE;
>>   	else
>> -		BUG();
>> +		panic("Reset register not defined for this SOC");
>>
>>   	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>>   	t = ath79_reset_rr(reg);
>> @@ -103,7 +103,7 @@ void ath79_device_reset_clear(u32 mask)
>>   	else if (soc_is_qca955x())
>>   		reg = QCA955X_RESET_REG_RESET_MODULE;
>>   	else
>> -		BUG();
>> +		panic("Reset register not defined for this SOC");
>>
>>   	spin_lock_irqsave(&ath79_device_reset_lock, flags);
>>   	t = ath79_reset_rr(reg);
>
> Looks more like the implementation of BUG() is wrong and gcc doesn't
> notice that BUG() won't return.
>
> Was this triggered by CONFIG_BUG=n?
>
>    Ralf
>

Hi Ralf,

Yes it was triggered by CONFIG_BUG=n

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
  2013-09-03 14:03     ` Markos Chandras
  (?)
@ 2013-09-18 13:45     ` Ralf Baechle
  2013-09-18 13:51       ` Ralf Baechle
  -1 siblings, 1 reply; 8+ messages in thread
From: Ralf Baechle @ 2013-09-18 13:45 UTC (permalink / raw)
  To: linux-kernel, Arnd Bergmann, David Howells, Markos Chandras; +Cc: linux-mips

On Tue, Sep 03, 2013 at 03:03:39PM +0100, Markos Chandras wrote:

> >Was this triggered by CONFIG_BUG=n?
> >
> >   Ralf
> >
> 
> Hi Ralf,
> 
> Yes it was triggered by CONFIG_BUG=n

So here's a small test case to demonstrate the issue:

/*
 * Definition of BUG taken from asm-generic/bug.h for the CONFIG_BUG=n case
 */
#define BUG() 	do {} while(0)

int foo(int arg)
{
	int res;

	if (arg == 1)
		res = 23;
	else if (arg -= 2)
		res = 42;
	else
		BUG();

	return res;
}

[ralf@h7 linux-mips]$ gcc -O2 -Wall -c bug.c 
bug.c: In function ‘foo’:
bug.c:17:2: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  return res;
  ^

It's fairly obvious to see what's happening here - GCC doesn't know that
the else case can not be reached, thus razorsharply concludes that res
may be used uninitialized.

I think the definition of BUG should be changed to something like

#define BUG()	unreachable()

This has the disadvantage of of expanding into a while (1) loop for older
compilers - but that's only for older compilers, relativly minor in
bloat and last I checked BUG() wasn't performance critical ;-)

  Ralf

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

 include/asm-generic/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 7d10f96..6f78771 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -108,7 +108,7 @@ extern void warn_slowpath_null(const char *file, const int line);
 
 #else /* !CONFIG_BUG */
 #ifndef HAVE_ARCH_BUG
-#define BUG() do {} while(0)
+#define BUG() unreachable()
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
  2013-09-18 13:45     ` Ralf Baechle
@ 2013-09-18 13:51       ` Ralf Baechle
  0 siblings, 0 replies; 8+ messages in thread
From: Ralf Baechle @ 2013-09-18 13:51 UTC (permalink / raw)
  To: linux-kernel, Arnd Bergmann, David Howells, Markos Chandras; +Cc: linux-mips

On Wed, Sep 18, 2013 at 03:45:33PM +0200, Ralf Baechle wrote:

> So here's a small test case to demonstrate the issue:
> 
> /*
>  * Definition of BUG taken from asm-generic/bug.h for the CONFIG_BUG=n case
>  */
> #define BUG() 	do {} while(0)
> 
> int foo(int arg)
> {
> 	int res;
> 
> 	if (arg == 1)
> 		res = 23;
> 	else if (arg -= 2)

I fatfingered the testcase while editing the email.  this line of course
is "else if (arg == 2)"

  Ralf

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-09-18 13:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-21 10:47 [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable Markos Chandras
2013-08-21 10:47 ` Markos Chandras
2013-08-21 16:40 ` Gabor Juhos
2013-09-03 13:38 ` Ralf Baechle
2013-09-03 14:03   ` Markos Chandras
2013-09-03 14:03     ` Markos Chandras
2013-09-18 13:45     ` Ralf Baechle
2013-09-18 13:51       ` Ralf Baechle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.