public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial/8250: fix uninitialized warnings
@ 2008-11-04 17:26 KOSAKI Motohiro
  2008-11-04 17:41 ` Alan Cox
  0 siblings, 1 reply; 8+ messages in thread
From: KOSAKI Motohiro @ 2008-11-04 17:26 UTC (permalink / raw)
  To: linux-serial, LKML; +Cc: kosaki.motohiro


fix following warnings.

drivers/serial/8250.c: In function ‘serial8250_shutdown’:
drivers/serial/8250.c:1612: warnings: ‘i’ may be used uninitialized in this function


Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
CC: linux-serial@vger.kernel.org
---
 drivers/serial/8250.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: b/drivers/serial/8250.c
===================================================================
--- a/drivers/serial/8250.c	2008-11-05 01:10:11.000000000 +0900
+++ b/drivers/serial/8250.c	2008-11-05 01:38:39.000000000 +0900
@@ -1609,7 +1609,7 @@ static int serial_link_irq_chain(struct 
 
 static void serial_unlink_irq_chain(struct uart_8250_port *up)
 {
-	struct irq_info *i;
+	struct irq_info *i = NULL;
 	struct hlist_node *n;
 	struct hlist_head *h;
 



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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-04 17:26 [PATCH] serial/8250: fix uninitialized warnings KOSAKI Motohiro
@ 2008-11-04 17:41 ` Alan Cox
  2008-11-05  4:51   ` KOSAKI Motohiro
  2008-11-10 22:30   ` Andrew Morton
  0 siblings, 2 replies; 8+ messages in thread
From: Alan Cox @ 2008-11-04 17:41 UTC (permalink / raw)
  Cc: linux-serial, LKML, kosaki.motohiro

On Wed, 5 Nov 2008 02:26:00 +0900 (JST)
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> 
> fix following warnings.
> 
> drivers/serial/8250.c: In function ‘serial8250_shutdown’:
> drivers/serial/8250.c:1612: warnings: ‘i’ may be used uninitialized in this function

NAK

This is an incorrect compiler warning. It's also one that current gcc
does not emit warnings for.

Alan

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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-04 17:41 ` Alan Cox
@ 2008-11-05  4:51   ` KOSAKI Motohiro
  2008-11-10 22:30   ` Andrew Morton
  1 sibling, 0 replies; 8+ messages in thread
From: KOSAKI Motohiro @ 2008-11-05  4:51 UTC (permalink / raw)
  To: Alan Cox; +Cc: kosaki.motohiro, linux-serial, LKML

> > fix following warnings.
> > 
> > drivers/serial/8250.c: In function ‘serial8250_shutdown’:
> > drivers/serial/8250.c:1612: warnings: ‘i’ may be used uninitialized in this function
> 
> NAK
> 
> This is an incorrect compiler warning. It's also one that current gcc
> does not emit warnings for.

I see.
Thanks!




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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-04 17:41 ` Alan Cox
  2008-11-05  4:51   ` KOSAKI Motohiro
@ 2008-11-10 22:30   ` Andrew Morton
  2008-11-10 23:47     ` Alan Cox
  2008-11-10 23:48     ` Alan Cox
  1 sibling, 2 replies; 8+ messages in thread
From: Andrew Morton @ 2008-11-10 22:30 UTC (permalink / raw)
  To: Alan Cox; +Cc: kosaki.motohiro, linux-serial, linux-kernel

On Tue, 4 Nov 2008 17:41:42 +0000
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> On Wed, 5 Nov 2008 02:26:00 +0900 (JST)
> KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
> 
> > 
> > fix following warnings.
> > 
> > drivers/serial/8250.c: In function ___serial8250_shutdown___:
> > drivers/serial/8250.c:1612: warnings: ___i___ may be used uninitialized in this function
> 
> NAK
> 
> This is an incorrect compiler warning. It's also one that current gcc
> does not emit warnings for.
> 

That's a regression in current gcc, surely?

static void serial_unlink_irq_chain(struct uart_8250_port *up)
{
	struct irq_info *i;
	struct hlist_node *n;
	struct hlist_head *h;

	mutex_lock(&hash_mutex);

	h = &irq_lists[up->port.irq % NR_IRQ_HASH];

	hlist_for_each(n, h) {
		i = hlist_entry(n, struct irq_info, node);
		if (i->irq == up->port.irq)
			break;
	}

	BUG_ON(n == NULL);
	BUG_ON(i->head == NULL);


#define hlist_for_each(pos, head) \
	for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
	     pos = pos->next)

hlist_for_each() can execute that loop zero times, in which case
serial_unlink_irq_chain will dereference an uninitialised variable.

Presumably the list shouldn't be empty at this stage, but this
is not particularly robust behaviour if that should happen..

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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-10 22:30   ` Andrew Morton
@ 2008-11-10 23:47     ` Alan Cox
  2008-11-10 23:48     ` Alan Cox
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Cox @ 2008-11-10 23:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: kosaki.motohiro, linux-serial, linux-kernel

> hlist_for_each() can execute that loop zero times, in which case
> serial_unlink_irq_chain will dereference an uninitialised variable.
> 
> Presumably the list shouldn't be empty at this stage, but this
> is not particularly robust behaviour if that should happen..

And the only cases that can trip are the more important BUG_ON() checks.
You could remove the BUG_ON() calls and make it less robust but that
seems slightly well silly to me ?

Alan

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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-10 22:30   ` Andrew Morton
  2008-11-10 23:47     ` Alan Cox
@ 2008-11-10 23:48     ` Alan Cox
  2008-11-10 23:58       ` Andrew Morton
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Cox @ 2008-11-10 23:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: kosaki.motohiro, linux-serial, linux-kernel

> That's a regression in current gcc, surely?

Oh and as a PS: Gcc is I believe right because if the loop is run zero
times then pos = NULL (ie n == NULL so the first BUG_ON fires)


Alan

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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-10 23:48     ` Alan Cox
@ 2008-11-10 23:58       ` Andrew Morton
  2008-11-11  0:19         ` David Miller
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2008-11-10 23:58 UTC (permalink / raw)
  To: Alan Cox; +Cc: kosaki.motohiro, linux-serial, linux-kernel

On Mon, 10 Nov 2008 23:48:43 +0000
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> > That's a regression in current gcc, surely?
> 
> Oh and as a PS: Gcc is I believe right because if the loop is run zero
> times then pos = NULL (ie n == NULL so the first BUG_ON fires)

Whoa.  That would be clever of it.


On about half the architectures, BUG is not considered to be no-return.
Dunno if that's a gcc shortcoming or if the architectures just haven't
implemented it properly yet.  This causes those architectures to
generate quite a few warnings in generic code which don't appear on
x86 (this would be one such case if your above theory is correct).

This is fairly irritating of those architectures, as I keep on going
in asking "what's up" and deciding "oh, that again".

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

* Re: [PATCH] serial/8250: fix uninitialized warnings
  2008-11-10 23:58       ` Andrew Morton
@ 2008-11-11  0:19         ` David Miller
  0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2008-11-11  0:19 UTC (permalink / raw)
  To: akpm; +Cc: alan, kosaki.motohiro, linux-serial, linux-kernel

From: Andrew Morton <akpm@linux-foundation.org>
Date: Mon, 10 Nov 2008 15:58:08 -0800

> On about half the architectures, BUG is not considered to be no-return.

Right, it ought to be, whether implicitly (__builtin_trap() is something
GCC considers no-return) or explicitly (if the arch uses inline
asm or the generic bug.h code)

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

end of thread, other threads:[~2008-11-11  0:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04 17:26 [PATCH] serial/8250: fix uninitialized warnings KOSAKI Motohiro
2008-11-04 17:41 ` Alan Cox
2008-11-05  4:51   ` KOSAKI Motohiro
2008-11-10 22:30   ` Andrew Morton
2008-11-10 23:47     ` Alan Cox
2008-11-10 23:48     ` Alan Cox
2008-11-10 23:58       ` Andrew Morton
2008-11-11  0:19         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox