diff mbox

xfs: Fix uninitialized variable in xfs_reflink_reserve_cow_range()

Message ID 1476699404-5977-1-git-send-email-geert@linux-m68k.org (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Geert Uytterhoeven Oct. 17, 2016, 10:16 a.m. UTC
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")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 fs/xfs/xfs_reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Darrick J. Wong Oct. 17, 2016, 6:36 p.m. UTC | #1
On Mon, Oct 17, 2016 at 12:16:44PM +0200, Geert Uytterhoeven wrote:
> 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")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

> ---
>  fs/xfs/xfs_reflink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index 5965e9455d91e036..d48a7cc2fe007f66 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -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);
>  
> -- 
> 1.9.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 5965e9455d91e036..d48a7cc2fe007f66 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -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);