Message ID | 20250410113858.149032-1-frank.li@vivo.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | btrfs: make error handling more appropriate in btrfs_delayed_ref_init() | expand |
On Thu, Apr 10, 2025 at 05:38:58AM -0600, Yangtao Li wrote: > 1. Remove unnecessary goto > 2. Make the execution logic of the function jumped by goto more appropriate > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > fs/btrfs/delayed-ref.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c > index 98c5b61dabe8..e984f1761afa 100644 > --- a/fs/btrfs/delayed-ref.c > +++ b/fs/btrfs/delayed-ref.c > @@ -1339,11 +1339,11 @@ int __init btrfs_delayed_ref_init(void) > { > btrfs_delayed_ref_head_cachep = KMEM_CACHE(btrfs_delayed_ref_head, 0); > if (!btrfs_delayed_ref_head_cachep) > - goto fail; > + return -ENOMEM; > > btrfs_delayed_ref_node_cachep = KMEM_CACHE(btrfs_delayed_ref_node, 0); > if (!btrfs_delayed_ref_node_cachep) > - goto fail; > + goto out; > > btrfs_delayed_extent_op_cachep = KMEM_CACHE(btrfs_delayed_extent_op, 0); > if (!btrfs_delayed_extent_op_cachep) > @@ -1351,6 +1351,8 @@ int __init btrfs_delayed_ref_init(void) > > return 0; > fail: > - btrfs_delayed_ref_exit(); > + kmem_cache_destroy(btrfs_delayed_ref_node_cachep); > +out: > + kmem_cache_destroy(btrfs_delayed_ref_head_cachep); This is partially duplicating btrfs_delayed_ref_exit(), I'd rather reuse the exit helper. I've checked if this can be done elsewhere, seems that there's only one other case btrfs_bioset_init(), which is partially duplicating btrfs_bioset_exit(). All other init/exit functions are trivial and allocate one structure. So if you want to do that cleanup, please update btrfs_bioset_init() to the preferred pattern. Thanks.
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 98c5b61dabe8..e984f1761afa 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -1339,11 +1339,11 @@ int __init btrfs_delayed_ref_init(void) { btrfs_delayed_ref_head_cachep = KMEM_CACHE(btrfs_delayed_ref_head, 0); if (!btrfs_delayed_ref_head_cachep) - goto fail; + return -ENOMEM; btrfs_delayed_ref_node_cachep = KMEM_CACHE(btrfs_delayed_ref_node, 0); if (!btrfs_delayed_ref_node_cachep) - goto fail; + goto out; btrfs_delayed_extent_op_cachep = KMEM_CACHE(btrfs_delayed_extent_op, 0); if (!btrfs_delayed_extent_op_cachep) @@ -1351,6 +1351,8 @@ int __init btrfs_delayed_ref_init(void) return 0; fail: - btrfs_delayed_ref_exit(); + kmem_cache_destroy(btrfs_delayed_ref_node_cachep); +out: + kmem_cache_destroy(btrfs_delayed_ref_head_cachep); return -ENOMEM; }
1. Remove unnecessary goto 2. Make the execution logic of the function jumped by goto more appropriate Signed-off-by: Yangtao Li <frank.li@vivo.com> --- fs/btrfs/delayed-ref.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)