Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: Improve error handling in xfs_mru_cache_create()
@ 2025-06-10 13:00 Markus Elfring
  2025-06-10 14:59 ` Darrick J. Wong
  2025-06-16 12:31 ` Carlos Maiolino
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2025-06-10 13:00 UTC (permalink / raw)
  To: linux-xfs, Carlos Maiolino
  Cc: LKML, kernel-janitors, Christoph Hellwig, Dave Chinner

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/xfs/xfs_mru_cache.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/fs/xfs/xfs_mru_cache.c b/fs/xfs/xfs_mru_cache.c
index 08443ceec329..2ed679a52e41 100644
--- a/fs/xfs/xfs_mru_cache.c
+++ b/fs/xfs/xfs_mru_cache.c
@@ -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;
 }
 
 /*
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-16 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 13:00 [PATCH] xfs: Improve error handling in xfs_mru_cache_create() Markus Elfring
2025-06-10 14:59 ` Darrick J. Wong
2025-06-16 12:31 ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox