Skip to contentSkip to conversation

xfs: Improve error handling in xfs_mru_cache_create()

PATCH Applied Markus Elfring 3 participants 3 messages Jun 10, 2025 – Jun 16, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 08443ceec329..2ed679a52e41 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 10 Jun 2025 14:50:07 +0200

Simplify 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.

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
index 08443ceec329..2ed679a52e41 100644
@@ -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
maintainer Applied
#2 lore raw
In reply to Markus Elfring
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]>