udf: initialize newblock to 0

Message ID 20221230175341.1629734-1-trix@redhat.com
State New
Headers
Series udf: initialize newblock to 0 |

Commit Message

Tom Rix Dec. 30, 2022, 5:53 p.m. UTC
  The clang build reports this error
fs/udf/inode.c:805:6: error: variable 'newblock' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
        if (*err < 0)
            ^~~~~~~~
newblock is never set before error handling jump.
Initialize newblock to 0 and remove redundant settings.

Fixes: d8b39db5fab8 ("udf: Handle error when adding extent to a file")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 fs/udf/inode.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
  

Comments

Jan Kara Jan. 2, 2023, 12:50 p.m. UTC | #1
On Fri 30-12-22 12:53:41, Tom Rix wrote:
> The clang build reports this error
> fs/udf/inode.c:805:6: error: variable 'newblock' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>         if (*err < 0)
>             ^~~~~~~~
> newblock is never set before error handling jump.
> Initialize newblock to 0 and remove redundant settings.
> 
> Fixes: d8b39db5fab8 ("udf: Handle error when adding extent to a file")
> Signed-off-by: Tom Rix <trix@redhat.com>

Thanks! I've added the patch to my tree.

								Honza

> ---
>  fs/udf/inode.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 4a912e2edcec..31965c3798f2 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -604,7 +604,7 @@ static sector_t inode_getblk(struct inode *inode, sector_t block,
>  	struct kernel_lb_addr eloc, tmpeloc;
>  	int c = 1;
>  	loff_t lbcount = 0, b_off = 0;
> -	udf_pblk_t newblocknum, newblock;
> +	udf_pblk_t newblocknum, newblock = 0;
>  	sector_t offset = 0;
>  	int8_t etype;
>  	struct udf_inode_info *iinfo = UDF_I(inode);
> @@ -710,7 +710,6 @@ static sector_t inode_getblk(struct inode *inode, sector_t block,
>  		ret = udf_do_extend_file(inode, &prev_epos, laarr, hole_len);
>  		if (ret < 0) {
>  			*err = ret;
> -			newblock = 0;
>  			goto out_free;
>  		}
>  		c = 0;
> @@ -775,7 +774,6 @@ static sector_t inode_getblk(struct inode *inode, sector_t block,
>  				goal, err);
>  		if (!newblocknum) {
>  			*err = -ENOSPC;
> -			newblock = 0;
>  			goto out_free;
>  		}
>  		if (isBeyondEOF)
> -- 
> 2.27.0
>
  

Patch

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 4a912e2edcec..31965c3798f2 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -604,7 +604,7 @@  static sector_t inode_getblk(struct inode *inode, sector_t block,
 	struct kernel_lb_addr eloc, tmpeloc;
 	int c = 1;
 	loff_t lbcount = 0, b_off = 0;
-	udf_pblk_t newblocknum, newblock;
+	udf_pblk_t newblocknum, newblock = 0;
 	sector_t offset = 0;
 	int8_t etype;
 	struct udf_inode_info *iinfo = UDF_I(inode);
@@ -710,7 +710,6 @@  static sector_t inode_getblk(struct inode *inode, sector_t block,
 		ret = udf_do_extend_file(inode, &prev_epos, laarr, hole_len);
 		if (ret < 0) {
 			*err = ret;
-			newblock = 0;
 			goto out_free;
 		}
 		c = 0;
@@ -775,7 +774,6 @@  static sector_t inode_getblk(struct inode *inode, sector_t block,
 				goal, err);
 		if (!newblocknum) {
 			*err = -ENOSPC;
-			newblock = 0;
 			goto out_free;
 		}
 		if (isBeyondEOF)