LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
@ 2007-03-28 16:47 Toralf Förster
  2007-03-28 16:56 ` Lee Revell
  0 siblings, 1 reply; 11+ messages in thread
From: Toralf Förster @ 2007-03-28 16:47 UTC (permalink / raw)
  To: andrea; +Cc: viro, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

I compiled current git source 2.6.21-rc5-g28defbe and got this warning:
...
fs/block_dev.c: In function `bd_claim_by_kobject':
fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
...

-- 
MfG/Sincerely

Toralf Förster

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 16:47 fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function Toralf Förster
@ 2007-03-28 16:56 ` Lee Revell
  2007-03-28 17:23   ` Jiri Kosina
  2007-03-30 19:40   ` Adrian Bunk
  0 siblings, 2 replies; 11+ messages in thread
From: Lee Revell @ 2007-03-28 16:56 UTC (permalink / raw)
  To: Toralf Förster; +Cc: andrea, viro, linux-kernel

On 3/28/07, Toralf Förster <toralf.foerster@gmx.de> wrote:
> I compiled current git source 2.6.21-rc5-g28defbe and got this warning:
> ...
> fs/block_dev.c: In function `bd_claim_by_kobject':
> fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
> ...
>

Most of these warnings are really GCC bugs.  Please examine the code
in question.

Lee

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 16:56 ` Lee Revell
@ 2007-03-28 17:23   ` Jiri Kosina
  2007-03-28 20:14     ` Andrew Morton
  2007-03-30 19:40   ` Adrian Bunk
  1 sibling, 1 reply; 11+ messages in thread
From: Jiri Kosina @ 2007-03-28 17:23 UTC (permalink / raw)
  To: Lee Revell, Andrew Morton; +Cc: Toralf Förster, andrea, viro, linux-kernel

On Wed, 28 Mar 2007, Lee Revell wrote:

> > I compiled current git source 2.6.21-rc5-g28defbe and got this warning:
> > ...
> > fs/block_dev.c: In function `bd_claim_by_kobject':
> > fs/block_dev.c:953: warning: 'found' might be used uninitialized in this
> > function
> > ...
> Most of these warnings are really GCC bugs.  Please examine the code
> in question.

Anyway imho this time gcc got it right?



From: Jiri Kosina <jkosina@suse.cz>

blockdev: bd_claim_by_kobject() could check value of unititalized pointer

Fixes this warning:

fs/block_dev.c: In function `bd_claim_by_kobject':
fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function

struct bd_holder *found is initialized only when bd_claim() returns zero. If it
returns nonzero, ptr stays uninitialized. Later the value of the pointer is checked.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>

diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 575076c..e87d84a 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -950,7 +950,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
 				struct kobject *kobj)
 {
 	int res;
-	struct bd_holder *bo, *found;
+	struct bd_holder *bo, *found = NULL;
 
 	if (!kobj)
 		return -EINVAL;

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 17:23   ` Jiri Kosina
@ 2007-03-28 20:14     ` Andrew Morton
  2007-03-28 21:59       ` Dan Aloni
  2007-03-30  3:16       ` Kyle Moffett
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew Morton @ 2007-03-28 20:14 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Lee Revell, Toralf Förster, andrea, viro, linux-kernel

On Wed, 28 Mar 2007 19:23:32 +0200 (CEST)
Jiri Kosina <jikos@jikos.cz> wrote:

> blockdev: bd_claim_by_kobject() could check value of unititalized pointer
> 
> Fixes this warning:
> 
> fs/block_dev.c: In function `bd_claim_by_kobject':
> fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
> 
> struct bd_holder *found is initialized only when bd_claim() returns zero. If it
> returns nonzero, ptr stays uninitialized. Later the value of the pointer is checked.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> 
> diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 575076c..e87d84a 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -950,7 +950,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
>  				struct kobject *kobj)
>  {
>  	int res;
> -	struct bd_holder *bo, *found;
> +	struct bd_holder *bo, *found = NULL;

that generates extra code and people get upset.

One approach which we could ue in here is

	struct bd_holder *found = found;  /* Suppress bogus gcc warning */

which (surprisingly) gcc will currently accept, and which shouldn't
generate more code, although I haven't verified this.


But it's all rather ad-hoc and unpleasant.  I tend to think that we should
come up with some standardised way of squashing this warning - something
which stands out when one is reading the code, like

	struct bd_holder *found;

	squash_bogus_uninit_warning(found);	/* useful comment goes here */

which is also unpleasant, but not as unpleasant as a screenful of warnings
which hide real problems, IMO.



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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 20:14     ` Andrew Morton
@ 2007-03-28 21:59       ` Dan Aloni
  2007-03-30  3:16       ` Kyle Moffett
  1 sibling, 0 replies; 11+ messages in thread
From: Dan Aloni @ 2007-03-28 21:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jiri Kosina, Lee Revell, Toralf F?rster, andrea, viro, linux-kernel

On Wed, Mar 28, 2007 at 01:14:54PM -0700, Andrew Morton wrote:
> On Wed, 28 Mar 2007 19:23:32 +0200 (CEST)
> Jiri Kosina <jikos@jikos.cz> wrote:
> 
> > blockdev: bd_claim_by_kobject() could check value of unititalized pointer
[..]
> > @@ -950,7 +950,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
> >  				struct kobject *kobj)
> >  {
> >  	int res;
> > -	struct bd_holder *bo, *found;
> > +	struct bd_holder *bo, *found = NULL;
> 
> that generates extra code and people get upset.

I, for one, not upset. On the contrary.

IMHO gcc should be smart enough to optimize that code properly with that 
"= NULL" added. 

BTW with gcc 4.1.2 on x86_64 that warning doesn't get emitted, and it 
generates the same exact code with or without " = NULL". One could aruge,
if people are upset about more code being generated because they use an 
older stable branch of gcc, it's _their_ problem.

> 	struct bd_holder *found;
> 
> 	squash_bogus_uninit_warning(found);	/* useful comment goes here */
> 
> which is also unpleasant, but not as unpleasant as a screenful of warnings
> which hide real problems, IMO.

If there was such 'squash_bogus_uninit_warning' macro exist and in use,
then this could have been a possible scenario:

  A) There's some 200-lines long function.
  B) It has a squash_bogus_uninit_warning() somewhere in the beginning.
  C) Someone commits a patch that uses an uninitialized variable on _some_
     cases and it doesn't generate a warning.
  D) You get an 'heisenbug', since that pointer might point to something
     that is dereferencable without a fault, etc.

I think that warnings of these kind (assuming that they are not generated
as a result of deficiencies in the latest stable version of gcc) exist
for a damn good reason - the code should be fixed and that warning 
shouldn't be bypassed in semi-nasty ways.

-- 
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 20:14     ` Andrew Morton
  2007-03-28 21:59       ` Dan Aloni
@ 2007-03-30  3:16       ` Kyle Moffett
  2007-03-30 19:47         ` Adrian Bunk
  1 sibling, 1 reply; 11+ messages in thread
From: Kyle Moffett @ 2007-03-30  3:16 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jiri Kosina, Lee Revell, Toralf Förster, andrea, viro, linux-kernel

On Mar 28, 2007, at 16:14:54, Andrew Morton wrote:
> On Wed, 28 Mar 2007 19:23:32 +0200 (CEST)
> Jiri Kosina <jikos@jikos.cz> wrote:
>
>> blockdev: bd_claim_by_kobject() could check value of unititalized  
>> pointer
>>
>> Fixes this warning:
>>
>> fs/block_dev.c: In function `bd_claim_by_kobject':
>> fs/block_dev.c:953: warning: 'found' might be used uninitialized  
>> in this function
>>
>> struct bd_holder *found is initialized only when bd_claim()  
>> returns zero. If it returns nonzero, ptr stays uninitialized.  
>> Later the value of the pointer is checked.
>
> that generates extra code and people get upset.
>
> One approach which we could ue in here is
>
> 	struct bd_holder *found = found;  /* Suppress bogus gcc warning */

Well, that would be correct except the warning is an actual kernel  
bug.  Read Jiri's message (which you also quoted):
> struct bd_holder *found is initialized only when bd_claim() returns  
> zero. If it returns nonzero, ptr stays uninitialized. Later the  
> value of the pointer is checked.

So in this case it has to be initialized to NULL or there's a  
potential BUG() lurking.

Cheers,
Kyle Moffett


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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-28 16:56 ` Lee Revell
  2007-03-28 17:23   ` Jiri Kosina
@ 2007-03-30 19:40   ` Adrian Bunk
  1 sibling, 0 replies; 11+ messages in thread
From: Adrian Bunk @ 2007-03-30 19:40 UTC (permalink / raw)
  To: Lee Revell; +Cc: Toralf Förster, andrea, viro, linux-kernel

On Wed, Mar 28, 2007 at 12:56:59PM -0400, Lee Revell wrote:
> On 3/28/07, Toralf Förster <toralf.foerster@gmx.de> wrote:
> >I compiled current git source 2.6.21-rc5-g28defbe and got this warning:
> >...
> >fs/block_dev.c: In function `bd_claim_by_kobject':
> >fs/block_dev.c:953: warning: 'found' might be used uninitialized in this 
> >function
> >...
> >
> 
> Most of these warnings are really GCC bugs.  Please examine the code
> in question.

The word "GCC bugs" is a bit hard for them.

gcc gives different warnings for code where it could prove that a 
variable gets used uninitialized and code where it's not sure whether a 
variable will always be used initialized.

There are even cases where it's technically impossible for gcc to 
determine that a variable always gets initialized.

And these "might be used uninitialized" warnings have already found 
several kernel bugs.

> Lee

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-30  3:16       ` Kyle Moffett
@ 2007-03-30 19:47         ` Adrian Bunk
  2007-03-31  3:09           ` Cong WANG
  2007-03-31  8:11           ` Toralf Förster
  0 siblings, 2 replies; 11+ messages in thread
From: Adrian Bunk @ 2007-03-30 19:47 UTC (permalink / raw)
  To: Kyle Moffett
  Cc: Andrew Morton, Jiri Kosina, Lee Revell, Toralf Förster,
	andrea, viro, linux-kernel

On Thu, Mar 29, 2007 at 11:16:39PM -0400, Kyle Moffett wrote:
> On Mar 28, 2007, at 16:14:54, Andrew Morton wrote:
> >On Wed, 28 Mar 2007 19:23:32 +0200 (CEST)
> >Jiri Kosina <jikos@jikos.cz> wrote:
> >
> >>blockdev: bd_claim_by_kobject() could check value of unititalized  
> >>pointer
> >>
> >>Fixes this warning:
> >>
> >>fs/block_dev.c: In function `bd_claim_by_kobject':
> >>fs/block_dev.c:953: warning: 'found' might be used uninitialized  
> >>in this function
> >>
> >>struct bd_holder *found is initialized only when bd_claim()  
> >>returns zero. If it returns nonzero, ptr stays uninitialized.  
> >>Later the value of the pointer is checked.
> >
> >that generates extra code and people get upset.
> >
> >One approach which we could ue in here is
> >
> >	struct bd_holder *found = found;  /* Suppress bogus gcc warning */
> 
> Well, that would be correct except the warning is an actual kernel  
> bug.  Read Jiri's message (which you also quoted):
> >struct bd_holder *found is initialized only when bd_claim() returns  
> >zero. If it returns nonzero, ptr stays uninitialized. Later the  
> >value of the pointer is checked.
> 
> So in this case it has to be initialized to NULL or there's a  
> potential BUG() lurking.


No, the code is correct and it's impossible that the variable ever gets 
read uninitialized.

And BTW, i386 gcc 4.1 doesn't give me a warning for this.
Toralf, which gcc version and architecture did you see this with?


> Cheers,
> Kyle Moffett

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-30 19:47         ` Adrian Bunk
@ 2007-03-31  3:09           ` Cong WANG
  2007-03-31  8:11           ` Toralf Förster
  1 sibling, 0 replies; 11+ messages in thread
From: Cong WANG @ 2007-03-31  3:09 UTC (permalink / raw)
  To: Adrian Bunk, linux-kernel, jikos, Andrew Morton

2007/3/31, Adrian Bunk <bunk@stusta.de>:
> On Thu, Mar 29, 2007 at 11:16:39PM -0400, Kyle Moffett wrote:
> > On Mar 28, 2007, at 16:14:54, Andrew Morton wrote:
> > >On Wed, 28 Mar 2007 19:23:32 +0200 (CEST)
> > >Jiri Kosina <jikos@jikos.cz> wrote:
> > >
> > >>blockdev: bd_claim_by_kobject() could check value of unititalized
> > >>pointer
> > >>
> > >>Fixes this warning:
> > >>
> > >>fs/block_dev.c: In function `bd_claim_by_kobject':
> > >>fs/block_dev.c:953: warning: 'found' might be used uninitialized
> > >>in this function
> > >>
> > >>struct bd_holder *found is initialized only when bd_claim()
> > >>returns zero. If it returns nonzero, ptr stays uninitialized.
> > >>Later the value of the pointer is checked.
> > >
> > >that generates extra code and people get upset.
> > >
> > >One approach which we could ue in here is
> > >
> > >     struct bd_holder *found = found;  /* Suppress bogus gcc warning */
> >
> > Well, that would be correct except the warning is an actual kernel
> > bug.  Read Jiri's message (which you also quoted):
> > >struct bd_holder *found is initialized only when bd_claim() returns
> > >zero. If it returns nonzero, ptr stays uninitialized. Later the
> > >value of the pointer is checked.
> >
> > So in this case it has to be initialized to NULL or there's a
> > potential BUG() lurking.
>
>
> No, the code is correct and it's impossible that the variable ever gets
> read uninitialized.
>
> And BTW, i386 gcc 4.1 doesn't give me a warning for this.
> Toralf, which gcc version and architecture did you see this with?
>

I am also using i386 gcc 4.1.1, and I did receive many warnings of
such kind yesterday. I think we should fix them.

And the reason for the existence of such things is we just want to use
them for writing first instead of reading, thus ignore the
initialization.

-- 
So Dark The Con Of Man.

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-30 19:47         ` Adrian Bunk
  2007-03-31  3:09           ` Cong WANG
@ 2007-03-31  8:11           ` Toralf Förster
  2007-03-31 14:04             ` Adrian Bunk
  1 sibling, 1 reply; 11+ messages in thread
From: Toralf Förster @ 2007-03-31  8:11 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Kyle Moffett, Andrew Morton, Jiri Kosina, Lee Revell, andrea,
	viro, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 471 bytes --]

Am Freitag, 30. März 2007 21:47 schrieb Adrian Bunk:
> 
> 
> No, the code is correct and it's impossible that the variable ever gets 
> read uninitialized.
> 
> And BTW, i386 gcc 4.1 doesn't give me a warning for this.
> Toralf, which gcc version and architecture did you see this with?

> cu
> Adrian
> 

Hi, I use currently the following version:

gcc version 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)

-- 
MfG/Sincerely

Toralf Förster

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function
  2007-03-31  8:11           ` Toralf Förster
@ 2007-03-31 14:04             ` Adrian Bunk
  0 siblings, 0 replies; 11+ messages in thread
From: Adrian Bunk @ 2007-03-31 14:04 UTC (permalink / raw)
  To: Toralf Förster
  Cc: Kyle Moffett, Andrew Morton, Jiri Kosina, Lee Revell, andrea,
	viro, linux-kernel

On Sat, Mar 31, 2007 at 10:11:27AM +0200, Toralf Förster wrote:
> Am Freitag, 30. März 2007 21:47 schrieb Adrian Bunk:
> > 
> > 
> > No, the code is correct and it's impossible that the variable ever gets 
> > read uninitialized.
> > 
> > And BTW, i386 gcc 4.1 doesn't give me a warning for this.
> > Toralf, which gcc version and architecture did you see this with?
> 
> > cu
> > Adrian
> > 
> 
> Hi, I use currently the following version:
> 
> gcc version 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)

For finding warnings it's better to use the latest gcc version - gcc is 
evalving, and more recent versions tend to both give more valid warnings 
and give less warnings for non-problems (like in this case).

> MfG/Sincerely
> 
> Toralf Förster

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

end of thread, other threads:[~2007-03-31 14:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-28 16:47 fs/block_dev.c:953: warning: 'found' might be used uninitialized in this function Toralf Förster
2007-03-28 16:56 ` Lee Revell
2007-03-28 17:23   ` Jiri Kosina
2007-03-28 20:14     ` Andrew Morton
2007-03-28 21:59       ` Dan Aloni
2007-03-30  3:16       ` Kyle Moffett
2007-03-30 19:47         ` Adrian Bunk
2007-03-31  3:09           ` Cong WANG
2007-03-31  8:11           ` Toralf Förster
2007-03-31 14:04             ` Adrian Bunk
2007-03-30 19:40   ` Adrian Bunk

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).