[PATCH 18/21] ext4: remove unnecessary goto in ext4_mb_mark_diskspace_used

Kemeng Shi posted 21 patches 2 years, 7 months ago
There is a newer version of this series
[PATCH 18/21] ext4: remove unnecessary goto in ext4_mb_mark_diskspace_used
Posted by Kemeng Shi 2 years, 7 months ago
When ext4_read_block_bitmap fails, we can return PTR_ERR(bitmap_bh) to
remove unnecessary NULL check of bitmap_bh.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index f9fc461b633f..7d6991af50d8 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3739,9 +3739,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
 
 	bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group);
 	if (IS_ERR(bitmap_bh)) {
-		err = PTR_ERR(bitmap_bh);
-		bitmap_bh = NULL;
-		goto out_err;
+		return PTR_ERR(bitmap_bh);
 	}
 
 	BUFFER_TRACE(bitmap_bh, "getting write access");
-- 
2.30.0
Re: [PATCH 18/21] ext4: remove unnecessary goto in ext4_mb_mark_diskspace_used
Posted by Ritesh Harjani (IBM) 2 years, 6 months ago
Kemeng Shi <shikemeng@huaweicloud.com> writes:

> When ext4_read_block_bitmap fails, we can return PTR_ERR(bitmap_bh) to
> remove unnecessary NULL check of bitmap_bh.

bitmap_bh is a local pointer variable. So not setting it to NULL is not
a problem. I guess for consistency in return error code paths the author
would have kept it this way, but since this is the first return from the
function in case of an error, hence it looks ok if we simply call
return PTR_ERR(bitmap_bh), rather than a goto out_err.

Hence this looks good to me. Feel free to add - 

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>


>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/mballoc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index f9fc461b633f..7d6991af50d8 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3739,9 +3739,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
>  
>  	bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group);
>  	if (IS_ERR(bitmap_bh)) {
> -		err = PTR_ERR(bitmap_bh);
> -		bitmap_bh = NULL;
> -		goto out_err;
> +		return PTR_ERR(bitmap_bh);
>  	}
>  
>  	BUFFER_TRACE(bitmap_bh, "getting write access");
> -- 
> 2.30.0
Re: [PATCH 18/21] ext4: remove unnecessary goto in ext4_mb_mark_diskspace_used
Posted by Ojaswin Mujoo 2 years, 7 months ago
On Fri, Feb 10, 2023 at 03:48:22AM +0800, Kemeng Shi wrote:
> When ext4_read_block_bitmap fails, we can return PTR_ERR(bitmap_bh) to
> remove unnecessary NULL check of bitmap_bh.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/mballoc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index f9fc461b633f..7d6991af50d8 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3739,9 +3739,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
>  
>  	bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group);
>  	if (IS_ERR(bitmap_bh)) {
> -		err = PTR_ERR(bitmap_bh);
> -		bitmap_bh = NULL;

It's probably trivial but the fact that we no longer have `bitmap_bh =
NULL` is making me a bit paranoid. Although I think it should be
okay but maybe someone else can help double check this :)

> -		goto out_err;
> +		return PTR_ERR(bitmap_bh);
>  	}
>  
>  	BUFFER_TRACE(bitmap_bh, "getting write access");
> -- 
> 2.30.0
>