* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
@ 2008-05-01 19:16 ` Matthew Wilcox
2008-05-01 19:43 ` Adrian Bunk
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2008-05-01 19:16 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 08:06:52PM +0100, Ricardo Martins wrote:
> This is my first patch for the Linux kernel. It fixes the following
> warnings given by gcc 4.3.0 about uninitialzed entities in mmap.c:
First, it's generally a bad idea to fix these warnings. They sometimes
obscure real bugs.
> I'd appreciate some feedback.
> * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
> - *
> + *
Don't mix whitespace changes with other changes.
> - struct vm_area_struct *vma, *prev;
> + struct vm_area_struct *vma, *prev = NULL;
gcc bug -- it's failing to notice that find_vma_prepare() will always
initialise pprev.
> - struct rb_node **rb_link, *rb_parent;
> + struct rb_node **rb_link = NULL, *rb_parent = NULL;
Likewise.
The other changes in your patch are either whitespace or fixes for the
same gcc problem.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
2008-05-01 19:16 ` Matthew Wilcox
@ 2008-05-01 19:43 ` Adrian Bunk
2008-05-01 19:54 ` Ricardo Martins
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2008-05-01 19:43 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 01:16:27PM -0600, Matthew Wilcox wrote:
> On Thu, May 01, 2008 at 08:06:52PM +0100, Ricardo Martins wrote:
> > This is my first patch for the Linux kernel. It fixes the following
> > warnings given by gcc 4.3.0 about uninitialzed entities in mmap.c:
>
> First, it's generally a bad idea to fix these warnings. They sometimes
> obscure real bugs.
>...
ACK
> > - struct vm_area_struct *vma, *prev;
> > + struct vm_area_struct *vma, *prev = NULL;
>
> gcc bug -- it's failing to notice that find_vma_prepare() will always
> initialise pprev.
>...
You miss the "return" inside the while() loop in find_vma_prepare().
I do not know whether the code is correct, but the answer is not that
easy.
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] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
2008-05-01 19:16 ` Matthew Wilcox
2008-05-01 19:43 ` Adrian Bunk
@ 2008-05-01 19:54 ` Ricardo Martins
2008-05-01 20:25 ` Matthew Wilcox
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Ricardo Martins @ 2008-05-01 19:54 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]
On Thu, 01 May 2008 13:16, Matthew Wilcox wrote:
> On Thu, May 01, 2008 at 08:06:52PM +0100, Ricardo Martins wrote:
> > This is my first patch for the Linux kernel. It fixes the following
> > warnings given by gcc 4.3.0 about uninitialzed entities in mmap.c:
>
> First, it's generally a bad idea to fix these warnings. They sometimes
> obscure real bugs.
I see.
> > I'd appreciate some feedback.
>
> > * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
> > - *
> > + *
>
> Don't mix whitespace changes with other changes.
Ok, it won't happen again.
> > - struct vm_area_struct *vma, *prev;
> > + struct vm_area_struct *vma, *prev = NULL;
>
> gcc bug -- it's failing to notice that find_vma_prepare() will always
> initialise pprev.
>
> > - struct rb_node **rb_link, *rb_parent;
> > + struct rb_node **rb_link = NULL, *rb_parent = NULL;
>
> Likewise.
Hmm, that crossed my mind and I thought it was weird that gcc was
complaining about it.
> The other changes in your patch are either whitespace or fixes for the
> same gcc problem.
Thanks for your feedback; it was very helpful, since I'm a C newbie.
Regards,
--
Ricardo Martins * scarybox.net * GPG key: 0x1308F1B4
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
` (2 preceding siblings ...)
2008-05-01 19:54 ` Ricardo Martins
@ 2008-05-01 20:25 ` Matthew Wilcox
2008-05-01 20:40 ` Adrian Bunk
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2008-05-01 20:25 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 10:43:25PM +0300, Adrian Bunk wrote:
> > > - struct vm_area_struct *vma, *prev;
> > > + struct vm_area_struct *vma, *prev = NULL;
> >
> > gcc bug -- it's failing to notice that find_vma_prepare() will always
> > initialise pprev.
> >...
>
> You miss the "return" inside the while() loop in find_vma_prepare().
>
> I do not know whether the code is correct, but the answer is not that
> easy.
You're right, it isn't that easy.
However, the code is not buggy. Just compare:
vma = vma_tmp;
if (vma_tmp->vm_start <= addr)
return vma;
with
munmap_back:
vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
if (vma && vma->vm_start < addr + len) {
if (do_munmap(mm, addr, len))
return -ENOMEM;
goto munmap_back;
}
Now, we know that addr + len does not wrap, and that len > 0, so we know
that this warning is incorrect. But it's not reasonable to expect gcc to
be able to deduce this.
See also the CERT warning threads recently on the GCC lists ;-)
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
` (3 preceding siblings ...)
2008-05-01 20:25 ` Matthew Wilcox
@ 2008-05-01 20:40 ` Adrian Bunk
2008-05-01 21:05 ` Matthew Wilcox
2008-05-01 21:13 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2008-05-01 20:40 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 02:25:33PM -0600, Matthew Wilcox wrote:
> On Thu, May 01, 2008 at 10:43:25PM +0300, Adrian Bunk wrote:
> > > > - struct vm_area_struct *vma, *prev;
> > > > + struct vm_area_struct *vma, *prev = NULL;
> > >
> > > gcc bug -- it's failing to notice that find_vma_prepare() will always
> > > initialise pprev.
> > >...
> >
> > You miss the "return" inside the while() loop in find_vma_prepare().
> >
> > I do not know whether the code is correct, but the answer is not that
> > easy.
>
> You're right, it isn't that easy.
>
> However, the code is not buggy. Just compare:
>
> vma = vma_tmp;
> if (vma_tmp->vm_start <= addr)
> return vma;
>
> with
>
> munmap_back:
> vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
> if (vma && vma->vm_start < addr + len) {
> if (do_munmap(mm, addr, len))
> return -ENOMEM;
> goto munmap_back;
> }
>
> Now, we know that addr + len does not wrap, and that len > 0, so we know
> that this warning is incorrect. But it's not reasonable to expect gcc to
> be able to deduce this.
>...
Can you submit a patch with your explanation that uses
uninitialized_var() to silence these warnings?
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] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
` (4 preceding siblings ...)
2008-05-01 20:40 ` Adrian Bunk
@ 2008-05-01 21:05 ` Matthew Wilcox
2008-05-01 21:13 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2008-05-01 21:05 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 11:40:37PM +0300, Adrian Bunk wrote:
> On Thu, May 01, 2008 at 02:25:33PM -0600, Matthew Wilcox wrote:
> > However, the code is not buggy. Just compare:
> >
> > vma = vma_tmp;
> > if (vma_tmp->vm_start <= addr)
> > return vma;
> >
> > with
> >
> > munmap_back:
> > vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
> > if (vma && vma->vm_start < addr + len) {
> > if (do_munmap(mm, addr, len))
> > return -ENOMEM;
> > goto munmap_back;
> > }
> >
> > Now, we know that addr + len does not wrap, and that len > 0, so we know
> > that this warning is incorrect. But it's not reasonable to expect gcc to
> > be able to deduce this.
> >...
>
> Can you submit a patch with your explanation that uses
> uninitialized_var() to silence these warnings?
I could, but I don't know if I want to. Suppose somebody changes the
code later to actually make prev used before it's initialised? Then we
would have GCC not warning about a problem.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/1] mmap: fix uninitialized entities warnings.
2008-05-01 19:06 [PATCH 1/1] mmap: fix uninitialized entities warnings Ricardo Martins
` (5 preceding siblings ...)
2008-05-01 21:05 ` Matthew Wilcox
@ 2008-05-01 21:13 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2008-05-01 21:13 UTC (permalink / raw)
To: kernel-janitors
On Thu, May 01, 2008 at 03:05:19PM -0600, Matthew Wilcox wrote:
> On Thu, May 01, 2008 at 11:40:37PM +0300, Adrian Bunk wrote:
> > On Thu, May 01, 2008 at 02:25:33PM -0600, Matthew Wilcox wrote:
> > > However, the code is not buggy. Just compare:
> > >
> > > vma = vma_tmp;
> > > if (vma_tmp->vm_start <= addr)
> > > return vma;
> > >
> > > with
> > >
> > > munmap_back:
> > > vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
> > > if (vma && vma->vm_start < addr + len) {
> > > if (do_munmap(mm, addr, len))
> > > return -ENOMEM;
> > > goto munmap_back;
> > > }
> > >
> > > Now, we know that addr + len does not wrap, and that len > 0, so we know
> > > that this warning is incorrect. But it's not reasonable to expect gcc to
> > > be able to deduce this.
> > >...
> >
> > Can you submit a patch with your explanation that uses
> > uninitialized_var() to silence these warnings?
>
> I could, but I don't know if I want to. Suppose somebody changes the
> code later to actually make prev used before it's initialised? Then we
> would have GCC not warning about a problem.
That's why we silence the warnings with uninitialized_var() - simply
change the #define and you'll see all silenced warnings.
The problem is that these warnings for which we know that the code is OK
today make it harder to spot where new warnings get added that might
indicate real bugs.
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] 8+ messages in thread