warnkill trivia 2/2
PATCH 1/1 warnkill trivia 2/2
2.4.20-pre5: prevent sparc32's atomic_read() from possibly discarding const qualifiers from pointers passed as its argument.
include/asm-sparc/atomic.h +1 -1
@@ -35,7 +35,7 @@#define ATOMIC_INIT (i) { (i << 8) } -static __inline__int atomic_read (atomic_t *v) +static __inline__int atomic_read (const atomic_t *v) {int ret = v->counter;
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 12:56:43 +0200
2.4.20-pre5: prevent sparc32's atomic_read() from possibly discarding const qualifiers from pointers passed as its argument.
-static __inline__ int atomic_read(atomic_t *v) +static __inline__ int atomic_read(const atomic_t *v)
So the atomic_t is const is it? That's news to me.
I think you mean something like "atomic_t const * v" which means the pointer is constant, not the value.
Quoted 6 lines
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 12:56:43 +02002.4.20-pre5: prevent sparc32's
atomic_read()from possibly discarding const qualifiers from pointers passed as its argument.
Quoted 7 lines
-static
__inline__intatomic_read(atomic_t *v)+static__inline__intatomic_read(const atomic_t *v)So the
atomic_tis const is it? That's news to me.I think you mean something like "
atomic_tconst * v" which means the pointer is constant, not the value.
Precisely.
include/asm-sparc/atomic.h +1 -1
@@ -35,7 +35,7 @@#define ATOMIC_INIT (i) { (i << 8) } -static __inline__int atomic_read (atomic_t *v) +static __inline__int atomic_read (atomic_t const *v) {int ret = v->counter;
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 13:28:56 +0200
Quoted 2 lines
I think you mean something like "
atomic_tconst * v" which means the pointer is constant, not the value.
Precisely.
BTW who even passes around const atomic_t's? Ie. what genrated the warning and made you even edit this to begin with?
Quoted 10 lines
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 13:28:56 +0200Quoted 2 lines
I think you mean something like "
atomic_tconst * v" which means the pointer is constant, not the value.Precisely.
BTW who even passes around const atomic_t's? Ie. what genrated the warning and made you even edit this to begin with?
fs/reiserfs/buffer2.c, line ~28:atomic_t gets the const quality on account of being a member of a const struct buffer_head instance.
void wait_buffer_until_released (const struct buffer_head * bh) {
int repeat_counter = 0;
while (atomic_read (&(bh->b_count)) > 1) { if ( !(++repeat_counter % 30000000) ) {
reiserfs_warning ("vs-3050: wait_buffer_until_released: nobody releases buffer (%b). Still waiting (%d) %cJDIRTY %cJWAIT\n",
bh, repeat_counter, buffer_journaled(bh) ? ' ' : '!',
buffer_journal_dirty(bh) ? ' ' : '!');
}
run_task_queue(&tq_disk);
yield();
}
if (repeat_counter > 30000000) {
reiserfs_warning("vs-3051: done waiting, ignore vs-3050 messages for (%b)\n", bh) ; }
}
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 13:37:42 +0200
Quoted 2 lines
BTW who even passes around const atomic_t's? Ie. what genrated the warning and made you even edit this to begin with?
fs/reiserfs/buffer2.c, line ~28:
atomic_t gets the const quality on account of being a member of a const struct buffer_head instance.
void wait_buffer_until_released (const struct buffer_head * bh)
{Reiserfs is buggy, it means struct buffer_head const * bh
Let's keep the sparc atomic_read() how it is so more bugs like this can be found.
Quoted 2 lines
Let's keep the sparc
atomic_read()how it is so more bugs like this can be found.
I don't know, though... scratching my head here -- Is GCC actually able to distinguish between 'const int *a' and 'int const *a'?
Because if 'int const *a' means that the pointer is constant but not the actual value it points to,
void a(int const *a) { *a = 1; }
shouldn't be generating 'warning: assignment of read-only location'. Right?
Quoted 1 line
Reiserfs is buggy, it means struct
buffer_headconst * bh
Okay so that gives us the third reiserfs patch of the day:
buffer2.c renamed from buffer2.c~ +1 -1
@@ -21,7 +21,7 @@hold we did free all buffers in tree balance structure (get_empty_nodes and get_nodes_for_preserving) or in path structure only (get_new_buffer) just before calling this */ -void wait_buffer_until_released (const struct buffer_head * bh) +void wait_buffer_until_released (struct buffer_head const *bh) {int repeat_counter =0 ;
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 14:10:53 +0200
Quoted 2 lines
Let's keep the sparc
atomic_read()how it is so more bugs like this can be found.
I don't know, though... scratching my head here -- Is GCC actually able to distinguish between 'const int *a' and 'int const *a'?
No I don't mean this in a "C" sense, I mean conceptually that marking an object const which has members which are volatile and updated asynchronously makes zero sense.
Quoted 6 lines
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 14:10:53 +0200Quoted 2 lines
Let's keep the sparc
atomic_read()how it is so more bugs like this can be found.
Quoted 6 lines
I don't know, though... scratching my head here -- Is GCC actually able to distinguish between 'const int *a' and 'int const *a'?
No I don't mean this in a "C" sense, I mean conceptually that marking an object const which has members which are volatile and updated asynchronously makes zero sense.
True.
I've been playing a bit with how gcc handles the const qualifiers and made an interesting discovery:
Trying to compile
typedef int *p_int;
void a(const p_int t) { *t = 0; }
void b(const p_int t) { t = (int *) 0; }
void c(const int *t) { *t = 0; }
void d(const int *t) { t = (int *) 0; }
void e(int const *t) { *t = 0; }
void f(int const *t) { t = (int *) 0; }
will give 'assignment of read-only location' warnings for b(), c() and e(), i.e. it's impossible to have a constant pointer to a non-constant value w/o using a qualified typedef.
W/o a typedef, gcc seems unable to tell the difference between 'const int *' and 'int const *' altogether. In case one needs a constant pointer to a constant value, something like this should do:
typedef const int *p_int;
void f(const p_int a);
Usable? I don't quite think so.
T.
Quoted 13 lines · Tomas Szepe
I've been playing a bit with how gcc handles the const qualifiers and made an interesting discovery:
Trying to compile
typedef int
*p_int;
voida(const p_int t){ *t = 0; }
voidb(const p_int t){ t = (int *) 0; }
voidc(const int *t){ *t = 0; }
voidd(const int *t){ t = (int *) 0; }
voide(int const *t){ *t = 0; }
voidf(int const *t){ t = (int *) 0; }
Quoted 4 lines
will give 'assignment of read-only location' warnings for
b(),c()ande(), i.e. it's impossible to have a constant pointer to a non-constant value w/o using a qualified typedef.
If you want a constant *pointer*, use:
void f(int* const t)
(read "f is a function, taking parameter constant pointer to int, returning void)
Quoted 2 lines
W/o a typedef, gcc seems unable to tell the difference between 'const int *' and 'int const *' altogether.
That's because there is no difference ("pointer to integer constant" vs "pointer to constant integer").
See http://untroubled.org/articles/cdecls.txt for one of the best references I've ever seen to understanding C type declarations.
Signature · 2 lines
Bruce Guenter <[email protected]> http://em.ca/~bruceg/ http://untroubled.org/ OpenPGP key: 699980E8 / D0B7 C8DD 365D A395 29DA 2E2A E96F B2DC 6999 80E8
Quoted 9 lines · Tomas Szepe
Quoted 9 lines
From: Tomas Szepe <[email protected]>
Date: Sun, 1 Sep 2002 12:56:43 +02002.4.20-pre5: prevent sparc32's
atomic_read()from possibly discarding const qualifiers from pointers passed as its argument.-static
__inline__intatomic_read(atomic_t *v)+static__inline__intatomic_read(const atomic_t *v)
Quoted 7 lines
Quoted 4 lines
So the
atomic_tis const is it? That's news to me.I think you mean something like "
atomic_tconst * v" which means the pointer is constant, not the value.Precisely.
No, you don't. Having the pointer constant means the symbolic argument can't be changed inside the function. But it means nothing at all to the caller, because the caller's variable itself is never changed by the call.
include/asm-sparc/atomic.h line 40
Quoted 12 lines
diff -u
linux-2.4.20-pre5/include/asm-sparc/atomic.hlinux-2.4.20-pre5.n/include/asm-sparc/atomic.hinclude/asm-sparc/atomic.h +1
-1@@ -35,7 +35,7 @@#define ATOMIC_INIT (i) { (i << 8) } -static __inline__int atomic_read (atomic_t *v) +static __inline__int atomic_read (atomic_t const *v) {int ret = v->counter;
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <[email protected]>
PATCH 1/1 warnkill trivia 2/2 (correction)
In reply to Tomas SzepeQuoted 2 lines
2.4.20-pre5: prevent sparc32's
atomic_read()from possibly discarding const qualifiers from pointers passed as its argument.
Ok, the only reasonable way to deal with the last reiserfs vs. sparc32 compilation warning is apparently to strip the const from the wait_buffer_until_released() prototype, as it doesn't make any sense there. Marcelo please disregard the atomic_read() patch and apply the following instead:
fs/reiserfs/buffer2.c +1 -1
@@ -21,7 +21,7 @@hold we did free all buffers in tree balance structure (get_empty_nodes and get_nodes_for_preserving) or in path structure only (get_new_buffer) just before calling this */ -void wait_buffer_until_released (const struct buffer_head * bh) +void wait_buffer_until_released (struct buffer_head *bh) {int repeat_counter =0 ;
include/linux/reiserfs_fs.h +1 -1
@@ -1845,7 +1847,7 @@/* buffer2.c */ struct buffer_head *reiserfs_getblk (kdev_t n_dev,int n_block,int n_size); -void wait_buffer_until_released (const struct buffer_head * bh); +void wait_buffer_until_released (struct buffer_head *bh);struct buffer_head *reiserfs_bread (struct super_block *super,int n_block,int n_size);