Filipe David Borba Manana
2013-Dec-13 19:39 UTC
[PATCH] Btrfs: fix use of uninitialized err variable
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 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Dec-16 14:34 UTC
Re: [PATCH] Btrfs: fix use of uninitialized err variable
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. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Filipe David Manana
2013-Dec-16 17:03 UTC
Re: [PATCH] Btrfs: fix use of uninitialized err variable
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." -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Dec-17 15:27 UTC
Re: [PATCH] Btrfs: fix use of uninitialized err variable
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. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Filipe David Manana
2013-Dec-17 15:36 UTC
Re: [PATCH] Btrfs: fix use of uninitialized err variable
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." -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html