xfs: Improve error handling in xfs_mru_cache_create()
Subsystems (2)
PATCH 1/1 xfs: Improve error handling in xfs_mru_cache_create()
From: Markus Elfring <[email protected]>
Date: Tue, 10 Jun 2025 14:50:07 +0200
Simplify error handling in this function implementation.
* Delete unnecessary pointer checks and variable assignments.
* Omit a redundant function call.
This issue was detected by using the Coccinelle software.
--- fs/xfs/xfs_mru_cache.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
fs/xfs/xfs_mru_cache.c +4 -11
@@ -320,7 +320,7 @@ xfs_mru_cache_create( xfs_mru_cache_free_func_t free_func) {struct xfs_mru_cache *mru =NULL ; -int err =0 , grp; +int grp;unsigned int grp_time;if (mrup)
@@ -341,8 +341,8 @@ xfs_mru_cache_create( mru->lists =kzalloc (mru->grp_count *sizeof (*mru->lists),GFP_KERNEL | __GFP_NOFAIL);if (!mru->lists) { - err = -ENOMEM ; - goto exit; +kfree (mru); +return -ENOMEM ; }for (grp =0 ; grp < mru->grp_count; grp++)
@@ -361,14 +361,7 @@ xfs_mru_cache_create( mru->free_func = free_func; mru->data = data; *mrup = mru; - -exit: -if (err && mru && mru->lists) -kfree (mru->lists); -if (err && mru) -kfree (mru); - -return err; +return 0 ; }/*
Signature · 1 line
2.49.0
Quoted 5 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 10 Jun 2025 14:50:07 +0200Simplify error handling in this function implementation.
Quoted 8 lines
* Delete unnecessary pointer checks and variable assignments.
* Omit a redundant function call.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Looks ok,
--D
Quoted 48 lines
--- fs/xfs/xfs_mru_cache.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)fs/xfs/xfs_mru_cache.c +4
-11@@ -320,7 +320,7 @@ xfs_mru_cache_create( xfs_mru_cache_free_func_t free_func) {struct xfs_mru_cache *mru =NULL ; -int err =0 , grp; +int grp;unsigned int grp_time;if (mrup)@@ -341,8 +341,8 @@ xfs_mru_cache_create( mru->lists =kzalloc (mru->grp_count *sizeof (*mru->lists),GFP_KERNEL | __GFP_NOFAIL);if (!mru->lists) { - err = -ENOMEM ; - goto exit; +kfree (mru); +return -ENOMEM ; }for (grp =0 ; grp < mru->grp_count; grp++)@@ -361,14 +361,7 @@ xfs_mru_cache_create( mru->free_func = free_func; mru->data = data; *mrup = mru; - -exit: -if (err && mru && mru->lists) -kfree (mru->lists); -if (err && mru) -kfree (mru); - -return err; +return 0 ; }/* Signature · 1 line
2.49.0
Quoted 8 lines · Markus Elfring
Simplify error handling in this function implementation.
* Delete unnecessary pointer checks and variable assignments.
* Omit a redundant function call.
[...]
Applied to for-next, thanks!
[1/1] xfs: Improve error handling in xfs_mru_cache_create()
commit: 19fa6e493a933c095f164230d3393d504216e052
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>