* [Compile Warning] 2.6.30-rc8 build
@ 2009-06-05 16:43 Michael S. Zick
2009-06-05 17:22 ` Roland Dreier
2009-06-05 18:01 ` Alan Cox
0 siblings, 2 replies; 12+ messages in thread
From: Michael S. Zick @ 2009-06-05 16:43 UTC (permalink / raw)
To: linux-kernel
Group,
To my reading of the function, I think gcc has a point:
drivers/serial/8250.c: In function 'serial8250_shutdown':
drivers/serial/8250.c:1685: warning: 'i' may be used uninitialized in this function
It does read as if the code might try to initialize
the 'lock' field of a null pointer.
Suggestions?
Mike
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Compile Warning] 2.6.30-rc8 build
@ 2009-06-05 16:50 Michael S. Zick
2009-06-05 17:28 ` Roland Dreier
0 siblings, 1 reply; 12+ messages in thread
From: Michael S. Zick @ 2009-06-05 16:50 UTC (permalink / raw)
To: linux-kernel
Group;
I can't argue with gcc on this one either:
drivers/scsi/sd.c: In function 'sd_read_capacity':
drivers/scsi/sd.c:1451: warning: comparison is always false due to limited range of data type
It reads to my eyes as if the function can never
select read_capacity_16 for very large devices.
Suggestions?
Mike
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 16:43 Michael S. Zick
@ 2009-06-05 17:22 ` Roland Dreier
2009-06-05 17:40 ` Michael S. Zick
2009-06-05 18:01 ` Alan Cox
1 sibling, 1 reply; 12+ messages in thread
From: Roland Dreier @ 2009-06-05 17:22 UTC (permalink / raw)
To: lkml; +Cc: linux-kernel
> To my reading of the function, I think gcc has a point:
>
> drivers/serial/8250.c: In function 'serial8250_shutdown':
> drivers/serial/8250.c:1685: warning: 'i' may be used uninitialized in this function
>
> It does read as if the code might try to initialize
> the 'lock' field of a null pointer.
The code in question is:
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);
if (list_empty(i->head))
free_irq(up->port.irq, i);
and if the hlist_for_each() doesn't find a matching irq_info to put in
i, then the BUG_ON(n == NULL) will kill the system. So there's no bug
although it is understandable that gcc can't see that.
(Not sure why you talk about "the 'lock' field of a null pointer" -- I
assume your gcc warns about the function serial8250_shutdown() because
it is inlining a function only called from a single location)
- R.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 16:50 [Compile Warning] 2.6.30-rc8 build Michael S. Zick
@ 2009-06-05 17:28 ` Roland Dreier
2009-06-05 17:49 ` Michael S. Zick
0 siblings, 1 reply; 12+ messages in thread
From: Roland Dreier @ 2009-06-05 17:28 UTC (permalink / raw)
To: lkml; +Cc: linux-kernel
> I can't argue with gcc on this one either:
>
> drivers/scsi/sd.c: In function 'sd_read_capacity':
> drivers/scsi/sd.c:1451: warning: comparison is always false due to limited range of data type
>
> It reads to my eyes as if the function can never
> select read_capacity_16 for very large devices.
The code is:
if ((sizeof(sdkp->capacity) > 4) &&
(sdkp->capacity > 0xffffffffULL)) {
sdkp->capacity is a sector_t, and <linux/types.h> has:
#ifdef CONFIG_LBD
typedef u64 sector_t;
typedef u64 blkcnt_t;
#else
typedef unsigned long sector_t;
typedef unsigned long blkcnt_t;
#endif
so if you don't set CONFIG_LBD on a 32-bit architecture, then you are
correct that sd.c won't ever hit the READ_CAPACITY(16) case, and the
kernel won't be able to handle large SCSI disks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 17:22 ` Roland Dreier
@ 2009-06-05 17:40 ` Michael S. Zick
2009-06-05 17:50 ` Roland Dreier
2009-06-05 18:06 ` Alan Cox
0 siblings, 2 replies; 12+ messages in thread
From: Michael S. Zick @ 2009-06-05 17:40 UTC (permalink / raw)
To: Roland Dreier; +Cc: linux-kernel
On Fri June 5 2009, Roland Dreier wrote:
> > To my reading of the function, I think gcc has a point:
> >
> > drivers/serial/8250.c: In function 'serial8250_shutdown':
> > drivers/serial/8250.c:1685: warning: 'i' may be used uninitialized in this function
> >
> > It does read as if the code might try to initialize
> > the 'lock' field of a null pointer.
>
> The code in question is:
>
> 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);
>
> if (list_empty(i->head))
> free_irq(up->port.irq, i);
>
> and if the hlist_for_each() doesn't find a matching irq_info to put in
> i, then the BUG_ON(n == NULL) will kill the system. So there's no bug
> although it is understandable that gcc can't see that.
>
> (Not sure why you talk about "the 'lock' field of a null pointer" -- I
> assume your gcc warns about the function serial8250_shutdown() because
> it is inlining a function only called from a single location)
>
Later in the code that gcc thought had the problem - -
where it tries to do a spinlock_init(i->lock).
Of course, I, just like gcc, did not know the machine had already died.
I'll stick an "i = something" at the top (NULL?) just to shut up gcc.
Mike
> - R.
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 17:28 ` Roland Dreier
@ 2009-06-05 17:49 ` Michael S. Zick
0 siblings, 0 replies; 12+ messages in thread
From: Michael S. Zick @ 2009-06-05 17:49 UTC (permalink / raw)
To: Roland Dreier; +Cc: linux-kernel
On Fri June 5 2009, Roland Dreier wrote:
>
> > I can't argue with gcc on this one either:
> >
> > drivers/scsi/sd.c: In function 'sd_read_capacity':
> > drivers/scsi/sd.c:1451: warning: comparison is always false due to limited range of data type
> >
> > It reads to my eyes as if the function can never
> > select read_capacity_16 for very large devices.
>
> The code is:
>
> if ((sizeof(sdkp->capacity) > 4) &&
> (sdkp->capacity > 0xffffffffULL)) {
>
> sdkp->capacity is a sector_t, and <linux/types.h> has:
>
> #ifdef CONFIG_LBD
> typedef u64 sector_t;
> typedef u64 blkcnt_t;
> #else
> typedef unsigned long sector_t;
> typedef unsigned long blkcnt_t;
> #endif
>
> so if you don't set CONFIG_LBD on a 32-bit architecture, then you are
> correct that sd.c won't ever hit the READ_CAPACITY(16) case, and the
> kernel won't be able to handle large SCSI disks.
>
>
Perhaps then let gcc coherce the test value into a local sector_t holder
to make the warning go away (it would still be protected by the >4 thing).
Not a problem here - NetBooks don't (yet) come with that big a disk. ;)
Thanks
Mike
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 17:40 ` Michael S. Zick
@ 2009-06-05 17:50 ` Roland Dreier
2009-06-05 18:06 ` Alan Cox
1 sibling, 0 replies; 12+ messages in thread
From: Roland Dreier @ 2009-06-05 17:50 UTC (permalink / raw)
To: lkml; +Cc: linux-kernel
> I'll stick an "i = something" at the top (NULL?) just to shut up gcc.
you can do uninitialized_var(i) as a zero-overhead way to handle this.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 16:43 Michael S. Zick
2009-06-05 17:22 ` Roland Dreier
@ 2009-06-05 18:01 ` Alan Cox
2009-06-05 21:57 ` Andrew Morton
1 sibling, 1 reply; 12+ messages in thread
From: Alan Cox @ 2009-06-05 18:01 UTC (permalink / raw)
To: lkml; +Cc: linux-kernel
On Fri, 5 Jun 2009 11:43:03 -0500
"Michael S. Zick" <lkml@morethan.org> wrote:
> Group,
>
> To my reading of the function, I think gcc has a point:
>
> drivers/serial/8250.c: In function 'serial8250_shutdown':
> drivers/serial/8250.c:1685: warning: 'i' may be used uninitialized in this function
>
> It does read as if the code might try to initialize
> the 'lock' field of a null pointer.
>
> Suggestions?
Newer gcc ? At least current gcc appears to correctly deduce the code is
safe.
Alan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 17:40 ` Michael S. Zick
2009-06-05 17:50 ` Roland Dreier
@ 2009-06-05 18:06 ` Alan Cox
1 sibling, 0 replies; 12+ messages in thread
From: Alan Cox @ 2009-06-05 18:06 UTC (permalink / raw)
To: lkml; +Cc: Roland Dreier, linux-kernel
> Of course, I, just like gcc, did not know the machine had already died.
> I'll stick an "i = something" at the top (NULL?) just to shut up gcc.
And it will not get merged. Current gcc understands the code perfectly
well.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 18:01 ` Alan Cox
@ 2009-06-05 21:57 ` Andrew Morton
2009-06-05 22:06 ` Alan Cox
0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2009-06-05 21:57 UTC (permalink / raw)
To: Alan Cox; +Cc: lkml, linux-kernel
On Fri, 5 Jun 2009 19:01:38 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> On Fri, 5 Jun 2009 11:43:03 -0500
> "Michael S. Zick" <lkml@morethan.org> wrote:
>
> > Group,
> >
> > To my reading of the function, I think gcc has a point:
> >
> > drivers/serial/8250.c: In function 'serial8250_shutdown':
> > drivers/serial/8250.c:1685: warning: 'i' may be used uninitialized in this function
> >
> > It does read as if the code might try to initialize
> > the 'lock' field of a null pointer.
> >
> > Suggestions?
>
> Newer gcc ? At least current gcc appears to correctly deduce the code is
> safe.
That's a gcc regression isn't it?
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;
}
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
pos = pos->next)
I don't think there's any way in which gcc can deduce that h->first is
non-zero on entry to that loop. Even if it inlines
serial_unlink_irq_chain() into serial8250_shutdown().
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 21:57 ` Andrew Morton
@ 2009-06-05 22:06 ` Alan Cox
2009-06-05 22:13 ` Andrew Morton
0 siblings, 1 reply; 12+ messages in thread
From: Alan Cox @ 2009-06-05 22:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: lkml, linux-kernel
> I don't think there's any way in which gcc can deduce that h->first is
> non-zero on entry to that loop. Even if it inlines
> serial_unlink_irq_chain() into serial8250_shutdown().
Why does it care ?
Suppose the list is empty, n is loaded with NULL
That follows the BUG_ON path which expands to include a function marked
as not returning
gcc is just rather smarter than your average cc
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Compile Warning] 2.6.30-rc8 build
2009-06-05 22:06 ` Alan Cox
@ 2009-06-05 22:13 ` Andrew Morton
0 siblings, 0 replies; 12+ messages in thread
From: Andrew Morton @ 2009-06-05 22:13 UTC (permalink / raw)
To: Alan Cox; +Cc: lkml, linux-kernel
On Fri, 5 Jun 2009 23:06:41 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > I don't think there's any way in which gcc can deduce that h->first is
> > non-zero on entry to that loop. Even if it inlines
> > serial_unlink_irq_chain() into serial8250_shutdown().
>
> Why does it care ?
>
> Suppose the list is empty, n is loaded with NULL
>
> That follows the BUG_ON path which expands to include a function marked
> as not returning
Ah, OK.
btw, I think there are still several architectures whose BUG() isn't
correctly set up to tell gcc that it doesn't return. Not that this is
a reason to change the serial code.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2009-06-05 22:14 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-05 16:50 [Compile Warning] 2.6.30-rc8 build Michael S. Zick
2009-06-05 17:28 ` Roland Dreier
2009-06-05 17:49 ` Michael S. Zick
-- strict thread matches above, loose matches on Subject: below --
2009-06-05 16:43 Michael S. Zick
2009-06-05 17:22 ` Roland Dreier
2009-06-05 17:40 ` Michael S. Zick
2009-06-05 17:50 ` Roland Dreier
2009-06-05 18:06 ` Alan Cox
2009-06-05 18:01 ` Alan Cox
2009-06-05 21:57 ` Andrew Morton
2009-06-05 22:06 ` Alan Cox
2009-06-05 22:13 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox