* [2.4.23-pre3] Possible bug in fs/buffer.c
@ 2003-09-08 15:15 Rolf Eike Beer
2003-09-08 15:42 ` Andreas Schwab
0 siblings, 1 reply; 9+ messages in thread
From: Rolf Eike Beer @ 2003-09-08 15:15 UTC (permalink / raw)
To: linux-kernel
This is __put_unused_buffer_head from fs/buffer.c, lines 1156 to 1171:
static void __put_unused_buffer_head(struct buffer_head * bh)
{
if (unlikely(buffer_attached(bh)))
BUG();
if (nr_unused_buffer_heads >= MAX_UNUSED_BUFFERS) {
kmem_cache_free(bh_cachep, bh);
} else {
bh->b_dev = B_FREE;
===> bh->b_blocknr = -1; <===
bh->b_this_page = NULL;
nr_unused_buffer_heads++;
bh->b_next_free = unused_list;
unused_list = bh;
}
}
In include/linux/fs.h "struct buffer_head" is defined this way:
struct buffer_head {
/* First cache line: */
struct buffer_head *b_next; /* Hash queue list */
unsigned long b_blocknr; /* block number */
...
So this line (and line 1205, which is the same) is either ugly (and someone
meant ~0UL or something similar) or completely bogus. Same way in
2.6.0-test4-bk10/fs/buffer.c, line 1031 (b_blocknr is a sector_t, which is an
unsigned long).
Comments?
Eike
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 15:15 [2.4.23-pre3] Possible bug in fs/buffer.c Rolf Eike Beer
@ 2003-09-08 15:42 ` Andreas Schwab
2003-09-08 15:58 ` Alan Cox
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2003-09-08 15:42 UTC (permalink / raw)
To: Rolf Eike Beer; +Cc: linux-kernel
Rolf Eike Beer <eike-kernel@sf-tec.de> writes:
> This is __put_unused_buffer_head from fs/buffer.c, lines 1156 to 1171:
>
>
> static void __put_unused_buffer_head(struct buffer_head * bh)
> {
> if (unlikely(buffer_attached(bh)))
> BUG();
> if (nr_unused_buffer_heads >= MAX_UNUSED_BUFFERS) {
> kmem_cache_free(bh_cachep, bh);
> } else {
> bh->b_dev = B_FREE;
> ===> bh->b_blocknr = -1; <===
> bh->b_this_page = NULL;
>
> nr_unused_buffer_heads++;
> bh->b_next_free = unused_list;
> unused_list = bh;
> }
> }
>
> In include/linux/fs.h "struct buffer_head" is defined this way:
>
> struct buffer_head {
> /* First cache line: */
> struct buffer_head *b_next; /* Hash queue list */
> unsigned long b_blocknr; /* block number */
> ...
>
> So this line (and line 1205, which is the same) is either ugly (and someone
> meant ~0UL or something similar) or completely bogus.
It's neither ugly, nor bogus. The only 100% reliable way to assign the
maximum value to an unsigned integer is to use -1.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 15:42 ` Andreas Schwab
@ 2003-09-08 15:58 ` Alan Cox
2003-09-08 16:04 ` Andreas Schwab
2003-09-08 16:12 ` Rolf Eike Beer
0 siblings, 2 replies; 9+ messages in thread
From: Alan Cox @ 2003-09-08 15:58 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Rolf Eike Beer, Linux Kernel Mailing List
On Llu, 2003-09-08 at 16:42, Andreas Schwab wrote:
> It's neither ugly, nor bogus. The only 100% reliable way to assign the
> maximum value to an unsigned integer is to use -1.
Its not 100% reliable either 8). Properly you should use the limits.h
values. The kernel assumes 2's complement so just adding a cast would
probably keep gcc happy
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 15:58 ` Alan Cox
@ 2003-09-08 16:04 ` Andreas Schwab
2003-09-08 22:13 ` J.A. Magallon
2003-09-09 0:53 ` Alan Cox
2003-09-08 16:12 ` Rolf Eike Beer
1 sibling, 2 replies; 9+ messages in thread
From: Andreas Schwab @ 2003-09-08 16:04 UTC (permalink / raw)
To: Alan Cox; +Cc: Rolf Eike Beer, Linux Kernel Mailing List
Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
> On Llu, 2003-09-08 at 16:42, Andreas Schwab wrote:
>> It's neither ugly, nor bogus. The only 100% reliable way to assign the
>> maximum value to an unsigned integer is to use -1.
>
> Its not 100% reliable either 8).
Could you please elaborate? Casting -1 to an unsigned type is guaranteed
to yield the maximum value for that type, at least since C89, but I think
even K&R C did get it right.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 15:58 ` Alan Cox
2003-09-08 16:04 ` Andreas Schwab
@ 2003-09-08 16:12 ` Rolf Eike Beer
2003-09-09 0:52 ` Alan Cox
1 sibling, 1 reply; 9+ messages in thread
From: Rolf Eike Beer @ 2003-09-08 16:12 UTC (permalink / raw)
To: Alan Cox; +Cc: Linux Kernel Mailing List, Andreas Schwab
Am Montag, 8. September 2003 17:58 schrieb Alan Cox:
> On Llu, 2003-09-08 at 16:42, Andreas Schwab wrote:
> > It's neither ugly, nor bogus. The only 100% reliable way to assign the
> > maximum value to an unsigned integer is to use -1.
>
> Its not 100% reliable either 8). Properly you should use the limits.h
> values. The kernel assumes 2's complement so just adding a cast would
> probably keep gcc happy
gcc didn't even find that. He complained about a line slightly above this one.
In limits.h there is no value equal to -1UL.
Eike
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 16:04 ` Andreas Schwab
@ 2003-09-08 22:13 ` J.A. Magallon
2003-09-09 0:53 ` Alan Cox
1 sibling, 0 replies; 9+ messages in thread
From: J.A. Magallon @ 2003-09-08 22:13 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Alan Cox, Rolf Eike Beer, Linux Kernel Mailing List
On 09.08, Andreas Schwab wrote:
> Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>
> > On Llu, 2003-09-08 at 16:42, Andreas Schwab wrote:
> >> It's neither ugly, nor bogus. The only 100% reliable way to assign the
> >> maximum value to an unsigned integer is to use -1.
> >
> > Its not 100% reliable either 8).
>
> Could you please elaborate? Casting -1 to an unsigned type is guaranteed
> to yield the maximum value for that type, at least since C89, but I think
> even K&R C did get it right.
>
Would not be much cleaner to do use ~0UL ?
--
J.A. Magallon <jamagallon@able.es> \ Software is like sex:
werewolf.able.es \ It's better when it's free
Mandrake Linux release 9.2 (Cooker) for i586
Linux 2.4.23-pre2-jam1m (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk))
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 16:12 ` Rolf Eike Beer
@ 2003-09-09 0:52 ` Alan Cox
0 siblings, 0 replies; 9+ messages in thread
From: Alan Cox @ 2003-09-09 0:52 UTC (permalink / raw)
To: Rolf Eike Beer; +Cc: Linux Kernel Mailing List, Andreas Schwab
On Llu, 2003-09-08 at 17:12, Rolf Eike Beer wrote:
> gcc didn't even find that. He complained about a line slightly above this one.
> In limits.h there is no value equal to -1UL.
UINT_MAX in a standard C limits.h. Right now I dont think the kernel
defines it but it could and ANSI C deals with this stuff.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-08 16:04 ` Andreas Schwab
2003-09-08 22:13 ` J.A. Magallon
@ 2003-09-09 0:53 ` Alan Cox
2003-09-09 13:39 ` Rolf Eike Beer
1 sibling, 1 reply; 9+ messages in thread
From: Alan Cox @ 2003-09-09 0:53 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Rolf Eike Beer, Linux Kernel Mailing List
On Llu, 2003-09-08 at 17:04, Andreas Schwab wrote:
> > Its not 100% reliable either 8).
>
> Could you please elaborate? Casting -1 to an unsigned type is guaranteed
> to yield the maximum value for that type, at least since C89, but I think
> even K&R C did get it right.
My error - its ~0 that is unreliable.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [2.4.23-pre3] Possible bug in fs/buffer.c
2003-09-09 0:53 ` Alan Cox
@ 2003-09-09 13:39 ` Rolf Eike Beer
0 siblings, 0 replies; 9+ messages in thread
From: Rolf Eike Beer @ 2003-09-09 13:39 UTC (permalink / raw)
To: Alan Cox; +Cc: Linux Kernel Mailing List, Andreas Schwab
Am Dienstag, 9. September 2003 02:53 schrieb Alan Cox:
> On Llu, 2003-09-08 at 17:04, Andreas Schwab wrote:
> > > Its not 100% reliable either 8).
> >
> > Could you please elaborate? Casting -1 to an unsigned type is guaranteed
> > to yield the maximum value for that type, at least since C89, but I think
> > even K&R C did get it right.
>
> My error - its ~0 that is unreliable.
Uh-oh:
eike@bilbo:/mnt/kernel/linux-2.4.23-pre3> grep -r "~0[^xX]" *| wc -l
713
Eike
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2003-09-09 13:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-08 15:15 [2.4.23-pre3] Possible bug in fs/buffer.c Rolf Eike Beer
2003-09-08 15:42 ` Andreas Schwab
2003-09-08 15:58 ` Alan Cox
2003-09-08 16:04 ` Andreas Schwab
2003-09-08 22:13 ` J.A. Magallon
2003-09-09 0:53 ` Alan Cox
2003-09-09 13:39 ` Rolf Eike Beer
2003-09-08 16:12 ` Rolf Eike Beer
2003-09-09 0:52 ` Alan Cox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).