Skip to contentSkip to conversation

xfs: Fix uninitialized variable in xfs_reflink_reserve_cow_range()

PATCH In review Geert Uytterhoeven 3 participants 4 messages Oct 17, 2016 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: Fix uninitialized variable in xfs_reflink_reserve_cow_range()

with gcc 4.1.2:

fs/xfs/xfs_reflink.c: In function ‘xfs_reflink_reserve_cow_range’:
fs/xfs/xfs_reflink.c:327: warning: ‘error’ may be used uninitialized in this function

Indeed, if "count" is zero, the function will return an uninitialized error value.

While "count" is unlikely to be zero, this function is called through the public iomap API. Hence fix this by preinitializing error to zero.

Fixes 2a06705cd5954030 ("xfs: create delalloc extents in CoW fork")
---
 fs/xfs/xfs_reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_reflink.c +1 -1
index 5965e9455d91e036..d48a7cc2fe007f66 100644
@@ -324,7 +324,7 @@
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb, end_fsb;
 	bool			skipped = false;
-	int			error;
+	int			error = 0;
 
 	trace_xfs_reflink_reserve_cow_range(ip, offset, count);
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Geert Uytterhoeven

with gcc 4.1.2:

fs/xfs/xfs_reflink.c: In function ‘xfs_reflink_reserve_cow_range’:
fs/xfs/xfs_reflink.c:327: warning: ‘error’ may be used uninitialized in this function

Indeed, if "count" is zero, the function will return an uninitialized error value.

While "count" is unlikely to be zero, this function is called through the public iomap API. Hence fix this by preinitializing error to zero.

The iomap API should never call in with a zero count, but I think the initialization is a fine safety net anyway:

Btw, what compiler did you get this from? I haven't seen it, but then again I recently missed a lot of initializers without compiler warnings, so either something changed in the Debian stable gcc or our build system recently..

#2 lore raw

Hi Christoph,

Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Geert Uytterhoeven

with gcc 4.1.2:

fs/xfs/xfs_reflink.c: In function ‘xfs_reflink_reserve_cow_range’:
fs/xfs/xfs_reflink.c:327: warning: ‘error’ may be used uninitialized in this function

Quoted 8 lines
Quoted 5 lines

Indeed, if "count" is zero, the function will return an uninitialized error value.

While "count" is unlikely to be zero, this function is called through the public iomap API. Hence fix this by preinitializing error to zero.

The iomap API should never call in with a zero count, but I think the initialization is a fine safety net anyway:

Exactly my thought.

Quoted 1 line

Thanks!

Quoted 4 lines

Btw, what compiler did you get this from? I haven't seen it, but then again I recently missed a lot of initializers without compiler warnings, so either something changed in the Debian stable gcc or our build system recently..

m68k-linux-gnu-gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)

Stoneage, but it did find 4 real bugs introduced in v4.9-rc1...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Reviewed-by on v1 1/1
#3 lore raw
In reply to Geert Uytterhoeven
Quoted 5 lines · Geert Uytterhoeven

with gcc 4.1.2:

fs/xfs/xfs_reflink.c: In function ‘xfs_reflink_reserve_cow_range’:
fs/xfs/xfs_reflink.c:327: warning: ‘error’ may be used uninitialized in this function

Quoted 8 lines

Indeed, if "count" is zero, the function will return an uninitialized error value.

While "count" is unlikely to be zero, this function is called through the public iomap API. Hence fix this by preinitializing error to zero.

Fixes 2a06705cd5954030 ("xfs: create delalloc extents in CoW fork")
Quoted 20 lines
---
 fs/xfs/xfs_reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_reflink.c +1 -1
index 5965e9455d91e036..d48a7cc2fe007f66 100644
@@ -324,7 +324,7 @@
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb, end_fsb;
 	bool			skipped = false;
-	int			error;
+	int			error = 0;
 
 	trace_xfs_reflink_reserve_cow_range(ip, offset, count);
 
Signature · 1 line
1.9.1