* [PATCH] Btrfs: fix use of uninitialized err variable
@ 2013-12-13 19:39 Filipe David Borba Manana
2013-12-16 14:34 ` David Sterba
0 siblings, 1 reply; 5+ messages in thread
From: Filipe David Borba Manana @ 2013-12-13 19:39 UTC (permalink / raw)
To: linux-btrfs; +Cc: Filipe David Borba Manana
>From the compiler:
fs/btrfs/file.c: In function ‘prepare_pages.isra.18’:
fs/btrfs/file.c:1265:6: warning: ‘err’ may be used uninitialized in this function [-Wuninitialized]
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
fs/btrfs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 740ae8c..35bf838 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1244,7 +1244,7 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages,
int i;
unsigned long index = pos >> PAGE_CACHE_SHIFT;
gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping);
- int err;
+ int err = 0;
int faili;
for (i = 0; i < num_pages; i++) {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Btrfs: fix use of uninitialized err variable
2013-12-13 19:39 [PATCH] Btrfs: fix use of uninitialized err variable Filipe David Borba Manana
@ 2013-12-16 14:34 ` David Sterba
2013-12-16 17:03 ` Filipe David Manana
0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2013-12-16 14:34 UTC (permalink / raw)
To: Filipe David Borba Manana; +Cc: linux-btrfs
On Fri, Dec 13, 2013 at 07:39:34PM +0000, Filipe David Borba Manana wrote:
> >From the compiler:
>
> fs/btrfs/file.c: In function ‘prepare_pages.isra.18’:
> fs/btrfs/file.c:1265:6: warning: ‘err’ may be used uninitialized in this function [-Wuninitialized]
My gcc 4.8.1 does not see this warning, nor do I while inspecting the
souces in current next-master.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Btrfs: fix use of uninitialized err variable
2013-12-16 14:34 ` David Sterba
@ 2013-12-16 17:03 ` Filipe David Manana
2013-12-17 15:27 ` David Sterba
0 siblings, 1 reply; 5+ messages in thread
From: Filipe David Manana @ 2013-12-16 17:03 UTC (permalink / raw)
To: dsterba@suse.cz, Filipe David Borba Manana,
linux-btrfs@vger.kernel.org
On Mon, Dec 16, 2013 at 2:34 PM, David Sterba <dsterba@suse.cz> wrote:
> On Fri, Dec 13, 2013 at 07:39:34PM +0000, Filipe David Borba Manana wrote:
>> >From the compiler:
>>
>> fs/btrfs/file.c: In function ‘prepare_pages.isra.18’:
>> fs/btrfs/file.c:1265:6: warning: ‘err’ may be used uninitialized in this function [-Wuninitialized]
>
> My gcc 4.8.1 does not see this warning, nor do I while inspecting the
> souces in current next-master.
Here it's gcc 4.6.3.
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Btrfs: fix use of uninitialized err variable
2013-12-16 17:03 ` Filipe David Manana
@ 2013-12-17 15:27 ` David Sterba
2013-12-17 15:36 ` Filipe David Manana
0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2013-12-17 15:27 UTC (permalink / raw)
To: Filipe David Manana; +Cc: dsterba@suse.cz, linux-btrfs@vger.kernel.org
On Mon, Dec 16, 2013 at 05:03:25PM +0000, Filipe David Manana wrote:
> On Mon, Dec 16, 2013 at 2:34 PM, David Sterba <dsterba@suse.cz> wrote:
> > On Fri, Dec 13, 2013 at 07:39:34PM +0000, Filipe David Borba Manana wrote:
> >> >From the compiler:
> >>
> >> fs/btrfs/file.c: In function ‘prepare_pages.isra.18’:
> >> fs/btrfs/file.c:1265:6: warning: ‘err’ may be used uninitialized in this function [-Wuninitialized]
> >
> > My gcc 4.8.1 does not see this warning, nor do I while inspecting the
> > souces in current next-master.
>
> Here it's gcc 4.6.3.
I've seen that some versions of gcc produce bogus warnings of that sort
and manual review is needed, but I haven't found a code path that would
lead to uninitialized use of err.
The warning points to
1259 if (i == 0)
1260 err = prepare_uptodate_page(pages[i], pos,
1261 force_uptodate);
1262 if (i == num_pages - 1)
1263 err = prepare_uptodate_page(pages[i],
1264 pos + write_bytes, false);
1265 if (err) {
^^^^
1266 page_cache_release(pages[i]);
1267 faili = i - 1;
1268 goto fail;
1269 }
But the loop starts from i = 0 and the variable is initialized before
the check. So ti's gcc that does not see that, not a real error.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Btrfs: fix use of uninitialized err variable
2013-12-17 15:27 ` David Sterba
@ 2013-12-17 15:36 ` Filipe David Manana
0 siblings, 0 replies; 5+ messages in thread
From: Filipe David Manana @ 2013-12-17 15:36 UTC (permalink / raw)
To: dsterba@suse.cz, Filipe David Manana, linux-btrfs@vger.kernel.org
On Tue, Dec 17, 2013 at 3:27 PM, David Sterba <dsterba@suse.cz> wrote:
> On Mon, Dec 16, 2013 at 05:03:25PM +0000, Filipe David Manana wrote:
>> On Mon, Dec 16, 2013 at 2:34 PM, David Sterba <dsterba@suse.cz> wrote:
>> > On Fri, Dec 13, 2013 at 07:39:34PM +0000, Filipe David Borba Manana wrote:
>> >> >From the compiler:
>> >>
>> >> fs/btrfs/file.c: In function ‘prepare_pages.isra.18’:
>> >> fs/btrfs/file.c:1265:6: warning: ‘err’ may be used uninitialized in this function [-Wuninitialized]
>> >
>> > My gcc 4.8.1 does not see this warning, nor do I while inspecting the
>> > souces in current next-master.
>>
>> Here it's gcc 4.6.3.
>
> I've seen that some versions of gcc produce bogus warnings of that sort
> and manual review is needed, but I haven't found a code path that would
> lead to uninitialized use of err.
>
> The warning points to
>
> 1259 if (i == 0)
> 1260 err = prepare_uptodate_page(pages[i], pos,
> 1261 force_uptodate);
> 1262 if (i == num_pages - 1)
> 1263 err = prepare_uptodate_page(pages[i],
> 1264 pos + write_bytes, false);
> 1265 if (err) {
> ^^^^
>
> 1266 page_cache_release(pages[i]);
> 1267 faili = i - 1;
> 1268 goto fail;
> 1269 }
>
> But the loop starts from i = 0 and the variable is initialized before
> the check. So ti's gcc that does not see that, not a real error.
Right, my intention was to silence a compiler warning. Should have
made it more explicit in the commit message title.
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-12-17 15:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-13 19:39 [PATCH] Btrfs: fix use of uninitialized err variable Filipe David Borba Manana
2013-12-16 14:34 ` David Sterba
2013-12-16 17:03 ` Filipe David Manana
2013-12-17 15:27 ` David Sterba
2013-12-17 15:36 ` Filipe David Manana
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).