diff mbox series

[v3,1/2] btrfs: qgroup: use goto style to handle error in add_delayed_ref().

Message ID 20240607143021.122220-1-sunjunchao2870@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v3,1/2] btrfs: qgroup: use goto style to handle error in add_delayed_ref(). | expand

Commit Message

Julian Sun June 7, 2024, 2:30 p.m. UTC
Clean up resources using goto to get rid of repeated code.

Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
---
 fs/btrfs/delayed-ref.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Julian Sun June 17, 2024, 2:08 a.m. UTC | #1
Friendly ping...

Junchao Sun <sunjunchao2870@gmail.com> 于2024年6月7日周五 22:30写道:
>
> Clean up resources using goto to get rid of repeated code.
>
> Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
> ---
>  fs/btrfs/delayed-ref.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 6cc80fb10da2..1a41ab991738 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -1041,18 +1041,13 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
>                 return -ENOMEM;
>
>         head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS);
> -       if (!head_ref) {
> -               kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> -               return -ENOMEM;
> -       }
> +       if (!head_ref)
> +               goto free_node;
>
>         if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) {
>                 record = kzalloc(sizeof(*record), GFP_NOFS);
> -               if (!record) {
> -                       kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> -                       kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
> -                       return -ENOMEM;
> -               }
> +               if (!record)
> +                       goto free_head_ref;
>         }
>
>         init_delayed_ref_common(fs_info, node, generic_ref);
> @@ -1088,6 +1083,12 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
>         if (qrecord_inserted)
>                 return btrfs_qgroup_trace_extent_post(trans, record);
>         return 0;
> +
> +free_head_ref:
> +       kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
> +free_node:
> +       kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> +       return -ENOMEM;
>  }
>
>  /*
> --
> 2.39.2
>
Qu Wenruo June 17, 2024, 3:08 a.m. UTC | #2
在 2024/6/8 00:00, Junchao Sun 写道:
> Clean up resources using goto to get rid of repeated code.
>
> Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/delayed-ref.c | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 6cc80fb10da2..1a41ab991738 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -1041,18 +1041,13 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
>   		return -ENOMEM;
>
>   	head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS);
> -	if (!head_ref) {
> -		kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> -		return -ENOMEM;
> -	}
> +	if (!head_ref)
> +		goto free_node;
>
>   	if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) {
>   		record = kzalloc(sizeof(*record), GFP_NOFS);
> -		if (!record) {
> -			kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> -			kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
> -			return -ENOMEM;
> -		}
> +		if (!record)
> +			goto free_head_ref;
>   	}
>
>   	init_delayed_ref_common(fs_info, node, generic_ref);
> @@ -1088,6 +1083,12 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
>   	if (qrecord_inserted)
>   		return btrfs_qgroup_trace_extent_post(trans, record);
>   	return 0;
> +
> +free_head_ref:
> +	kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
> +free_node:
> +	kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
> +	return -ENOMEM;
>   }
>
>   /*
David Sterba Aug. 13, 2024, 10:44 p.m. UTC | #3
On Fri, Jun 07, 2024 at 10:30:20PM +0800, Junchao Sun wrote:
> Clean up resources using goto to get rid of repeated code.
> 
> Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>

I had the patches in my testing branches, no problems so far so I'm
adding it for 6.12. Thanks.
Julian Sun Aug. 16, 2024, 3:36 a.m. UTC | #4
David Sterba <dsterba@suse.cz> 于2024年8月14日周三 06:44写道:
>
> On Fri, Jun 07, 2024 at 10:30:20PM +0800, Junchao Sun wrote:
> > Clean up resources using goto to get rid of repeated code.
> >
> > Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
>
> I had the patches in my testing branches, no problems so far so I'm
> adding it for 6.12. Thanks.
I just noticed I missed a commit for a file. Sorry for the oversight.
Should I send a new version of the patch?

--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -125,7 +125,6 @@ struct btrfs_inode;
  * Record a dirty extent, and info qgroup to update quota on it
  */
 struct btrfs_qgroup_extent_record {
-       struct rb_node node;
        u64 bytenr;
        u64 num_bytes;


Best regards,
David Sterba Aug. 16, 2024, 11:46 a.m. UTC | #5
On Fri, Aug 16, 2024 at 11:36:29AM +0800, Julian Sun wrote:
> David Sterba <dsterba@suse.cz> 于2024年8月14日周三 06:44写道:
> >
> > On Fri, Jun 07, 2024 at 10:30:20PM +0800, Junchao Sun wrote:
> > > Clean up resources using goto to get rid of repeated code.
> > >
> > > Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
> >
> > I had the patches in my testing branches, no problems so far so I'm
> > adding it for 6.12. Thanks.
> I just noticed I missed a commit for a file. Sorry for the oversight.
> Should I send a new version of the patch?

No need to, I'll update the commit, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 6cc80fb10da2..1a41ab991738 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -1041,18 +1041,13 @@  static int add_delayed_ref(struct btrfs_trans_handle *trans,
 		return -ENOMEM;
 
 	head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS);
-	if (!head_ref) {
-		kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
-		return -ENOMEM;
-	}
+	if (!head_ref)
+		goto free_node;
 
 	if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) {
 		record = kzalloc(sizeof(*record), GFP_NOFS);
-		if (!record) {
-			kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
-			kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
-			return -ENOMEM;
-		}
+		if (!record)
+			goto free_head_ref;
 	}
 
 	init_delayed_ref_common(fs_info, node, generic_ref);
@@ -1088,6 +1083,12 @@  static int add_delayed_ref(struct btrfs_trans_handle *trans,
 	if (qrecord_inserted)
 		return btrfs_qgroup_trace_extent_post(trans, record);
 	return 0;
+
+free_head_ref:
+	kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
+free_node:
+	kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
+	return -ENOMEM;
 }
 
 /*