2008-10-15 23:25:21

by Alex Chiang

[permalink] [raw]
Subject: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:

drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
uninitialized in this function

Signed-off-by: Alex Chiang <[email protected]>
---
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 5d312dc..4e27c68 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3222,7 +3222,7 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
int tries = 5;
struct ata_device *last_failed_dev = NULL;
struct ata_link *link;
- struct ata_device *dev;
+ struct ata_device *dev = NULL;

if (ap->flags & ATA_FLAG_DISABLED)
return;


2008-10-16 02:13:47

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

Alex Chiang wrote:
> Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
>
> drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
> drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
> uninitialized in this function
>
> Signed-off-by: Alex Chiang <[email protected]>

Nacked-by: Tejun Heo <[email protected]>

Some gcc versions complain about sata_via, others complain about
something else. Some versions complain about some iterator usages while
not complaining about others, but none of those complaints is actually
wrong or dangerous. I don't think adding = NULL whenever some version
of gcc complains is the right approach.

Thanks.

--
tejun

2008-10-16 03:40:53

by Alex Chiang

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

* Tejun Heo <[email protected]>:
> Alex Chiang wrote:
> > Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
> >
> > drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
> > drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
> > uninitialized in this function
> >
> > Signed-off-by: Alex Chiang <[email protected]>
>
> Nacked-by: Tejun Heo <[email protected]>
>
> Some gcc versions complain about sata_via, others complain
> about something else. Some versions complain about some
> iterator usages while not complaining about others, but none of
> those complaints is actually wrong or dangerous. I don't think
> adding = NULL whenever some version of gcc complains is the
> right approach.

Hm, ok.

I guess we don't want to sprinkle these around all over the place
just to solve cosmetic issues, which makes sense, but is there
some other approach we could take instead? Any suggestions? Or
just live with it?

/ac

2008-10-16 03:56:59

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

Alex Chiang wrote:
> * Tejun Heo <[email protected]>:
>> Alex Chiang wrote:
>>> Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
>>>
>>> drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
>>> drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
>>> uninitialized in this function
>>>
>>> Signed-off-by: Alex Chiang <[email protected]>
>> Nacked-by: Tejun Heo <[email protected]>
>>
>> Some gcc versions complain about sata_via, others complain
>> about something else. Some versions complain about some
>> iterator usages while not complaining about others, but none of
>> those complaints is actually wrong or dangerous. I don't think
>> adding = NULL whenever some version of gcc complains is the
>> right approach.
>
> Hm, ok.
>
> I guess we don't want to sprinkle these around all over the place
> just to solve cosmetic issues, which makes sense, but is there
> some other approach we could take instead? Any suggestions? Or
> just live with it?

I think the current policy is blaming gcc but I also added quite a few
bogus NULL initializations here and there and caught several bugs thanks
to those warnings. We can think about adding an additional annotation
with leading double underbars which indicate that certain pointer
arguments to functions expect (or are okay with) pointers to
uninitialized variables which should be able to remove many of those
spurious warnings (on the caller side, the compiler can ignore the
warning and on the callee side the compiler can check whether it's being
dereferenced without being written to). Does anyone know whether gcc
already has that type of annotation?

Thanks.

--
tejun

2008-10-16 06:02:32

by Elias Oltmanns

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

Tejun Heo <[email protected]> wrote:
> Alex Chiang wrote:
>> * Tejun Heo <[email protected]>:
>
>>> Alex Chiang wrote:
>>>> Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
>>>>
>>>> drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
>>>> drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
>>>> uninitialized in this function
>>>>
>>>> Signed-off-by: Alex Chiang <[email protected]>
>>> Nacked-by: Tejun Heo <[email protected]>
>>>
>>> Some gcc versions complain about sata_via, others complain
>>> about something else. Some versions complain about some
>>> iterator usages while not complaining about others, but none of
>>> those complaints is actually wrong or dangerous. I don't think
>>> adding = NULL whenever some version of gcc complains is the
>>> right approach.
>>
>> Hm, ok.
>>
>> I guess we don't want to sprinkle these around all over the place
>> just to solve cosmetic issues, which makes sense, but is there
>> some other approach we could take instead? Any suggestions? Or
>> just live with it?
>
> I think the current policy is blaming gcc but I also added quite a few
> bogus NULL initializations here and there and caught several bugs thanks
> to those warnings. We can think about adding an additional annotation
> with leading double underbars which indicate that certain pointer
> arguments to functions expect (or are okay with) pointers to
> uninitialized variables which should be able to remove many of those
> spurious warnings (on the caller side, the compiler can ignore the
> warning and on the callee side the compiler can check whether it's being
> dereferenced without being written to). Does anyone know whether gcc
> already has that type of annotation?

Well, I don't know of this particular kind of annotation. However, I
don't quite see how that would solve the reported issue. Here, dev is a
local variable and the warning is generated due to the line

if (dev != last_failed_dev) {

For this sort of thing we have:

struct ata_device *uninitialized_var(dev);

Or is that precisely the thing you did *not* want?

Regards,

Elias

2008-10-16 06:12:13

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

Elias Oltmanns wrote:
>> I think the current policy is blaming gcc but I also added quite a few
>> bogus NULL initializations here and there and caught several bugs thanks
>> to those warnings. We can think about adding an additional annotation
>> with leading double underbars which indicate that certain pointer
>> arguments to functions expect (or are okay with) pointers to
>> uninitialized variables which should be able to remove many of those
>> spurious warnings (on the caller side, the compiler can ignore the
>> warning and on the callee side the compiler can check whether it's being
>> dereferenced without being written to). Does anyone know whether gcc
>> already has that type of annotation?
>
> Well, I don't know of this particular kind of annotation. However, I
> don't quite see how that would solve the reported issue.

I was thinking about the warning in sata_via.c and for such cases the
compiler doesn't have any other way of figuring out whether it's okay
or not (the sata_via case, the compiler can actually do as the callee
is in the same file but you know what I mean).

> Here, dev is a local variable and the warning is generated due to
> the line
>
> if (dev != last_failed_dev) {
>
> For this sort of thing we have:
>
> struct ata_device *uninitialized_var(dev);

Ah.. thanks.

> Or is that precisely the thing you did *not* want?

I don't know. Later versions of gcc doesn't issue warning because it
knows "if (!link)" always triggers if dev is not initialized. I don't
think we should be adding those annotations if the current gen
compiler can already figure that out as it only decreases
debuggability when something actually gets broken there.

Thanks.

--
tejun

2008-10-16 06:19:44

by Adrian Bunk

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

On Wed, Oct 15, 2008 at 09:40:42PM -0600, Alex Chiang wrote:
> * Tejun Heo <[email protected]>:
> > Alex Chiang wrote:
> > > Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
> > >
> > > drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
> > > drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
> > > uninitialized in this function
> > >
> > > Signed-off-by: Alex Chiang <[email protected]>
> >
> > Nacked-by: Tejun Heo <[email protected]>
> >
> > Some gcc versions complain about sata_via, others complain
> > about something else. Some versions complain about some
> > iterator usages while not complaining about others, but none of
> > those complaints is actually wrong or dangerous. I don't think
> > adding = NULL whenever some version of gcc complains is the
> > right approach.
>
> Hm, ok.
>
> I guess we don't want to sprinkle these around all over the place
> just to solve cosmetic issues, which makes sense, but is there
> some other approach we could take instead? Any suggestions? Or
> just live with it?

We have an annotation for these kinds of warnings in the kernel.

But we'll never get a warning-free compilation with all seven (sic)
supported gcc release series.

A warning-free compilation with gcc 4.3 is worth some efforts, but
cluttering our code to fix bogus warnings with older gcc versions
is not a good thing.

> /ac

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

2008-10-16 21:21:33

by Alex Chiang

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

* Adrian Bunk <[email protected]>:
> On Wed, Oct 15, 2008 at 09:40:42PM -0600, Alex Chiang wrote:
> > * Tejun Heo <[email protected]>:
> > > Alex Chiang wrote:
> > > > Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
> > > >
> > > > drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
> > > > drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
> > > > uninitialized in this function
> > > >
> > > > Signed-off-by: Alex Chiang <[email protected]>
> > >
> > > Nacked-by: Tejun Heo <[email protected]>
> > >
> > > Some gcc versions complain about sata_via, others complain
> > > about something else. Some versions complain about some
> > > iterator usages while not complaining about others, but none of
> > > those complaints is actually wrong or dangerous. I don't think
> > > adding = NULL whenever some version of gcc complains is the
> > > right approach.
> >
> > Hm, ok.
> >
> > I guess we don't want to sprinkle these around all over the place
> > just to solve cosmetic issues, which makes sense, but is there
> > some other approach we could take instead? Any suggestions? Or
> > just live with it?
>
> We have an annotation for these kinds of warnings in the kernel.

What is the annotation?

> But we'll never get a warning-free compilation with all seven (sic)
> supported gcc release series.
>
> A warning-free compilation with gcc 4.3 is worth some efforts, but
> cluttering our code to fix bogus warnings with older gcc versions
> is not a good thing.

Ok, I already agree with this point.

Thanks.

/ac

2008-10-16 21:22:55

by Alex Chiang

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

* Adrian Bunk <[email protected]>:
> On Wed, Oct 15, 2008 at 09:40:42PM -0600, Alex Chiang wrote:
> > * Tejun Heo <[email protected]>:
> > > Alex Chiang wrote:
> > > > Shuts up gcc-3.4.5-glibc-2.3.6 when it complains of:
> > > >
> > > > drivers/ata/libata-scsi.c: In function `ata_scsi_scan_host':
> > > > drivers/ata/libata-scsi.c:3225: warning: 'dev' might be used
> > > > uninitialized in this function
> > > >
> > > > Signed-off-by: Alex Chiang <[email protected]>
> > >
> > > Nacked-by: Tejun Heo <[email protected]>
> > >
> > > Some gcc versions complain about sata_via, others complain
> > > about something else. Some versions complain about some
> > > iterator usages while not complaining about others, but none of
> > > those complaints is actually wrong or dangerous. I don't think
> > > adding = NULL whenever some version of gcc complains is the
> > > right approach.
> >
> > Hm, ok.
> >
> > I guess we don't want to sprinkle these around all over the place
> > just to solve cosmetic issues, which makes sense, but is there
> > some other approach we could take instead? Any suggestions? Or
> > just live with it?
>
> We have an annotation for these kinds of warnings in the kernel.

Oh, is it this?

from linux/compiler-gcc3.h
#define uninitialized_var(x) x = x

/ac

2008-10-16 21:24:40

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] stop gcc warning about uninitialized 'dev' in ata_scsi_scan_host

> > > I guess we don't want to sprinkle these around all over the place
> > > just to solve cosmetic issues, which makes sense, but is there
> > > some other approach we could take instead? Any suggestions? Or
> > > just live with it?
> >
> > We have an annotation for these kinds of warnings in the kernel.
>
> Oh, is it this?
>
> from linux/compiler-gcc3.h
> #define uninitialized_var(x) x = x

Yes, you got it.

--
~Randy