mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xfs: remove dead NULL check after __GFP_NOFAIL allocation
@ 2026-06-24 13:51 Gou Hao
  2026-06-25  8:42 ` Carlos Maiolino
  0 siblings, 1 reply; 2+ messages in thread
From: Gou Hao @ 2026-06-24 13:51 UTC (permalink / raw)
  To: cem, djwong, hch, kees; +Cc: linux-kernel, gouhaojake, kernel, linux-xfs

kmalloc with the __GFP_NOFAIL flag will never return NULL, so the
subsequent ENOMEM check is unreachable dead code. Remove it.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 fs/xfs/libxfs/xfs_dir2.c     | 12 ------------
 fs/xfs/libxfs/xfs_exchmaps.c |  5 -----
 fs/xfs/xfs_buf.c             |  3 ---
 fs/xfs/xfs_mru_cache.c       |  8 --------
 4 files changed, 28 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
index 0c0402a29b6b..6009ec26843d 100644
--- a/fs/xfs/libxfs/xfs_dir2.c
+++ b/fs/xfs/libxfs/xfs_dir2.c
@@ -249,9 +249,6 @@ xfs_dir_init(
 		return error;
 
 	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
-	if (!args)
-		return -ENOMEM;
-
 	args->geo = dp->i_mount->m_dir_geo;
 	args->dp = dp;
 	args->trans = tp;
@@ -342,9 +339,6 @@ xfs_dir_createname(
 	}
 
 	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
-	if (!args)
-		return -ENOMEM;
-
 	args->geo = dp->i_mount->m_dir_geo;
 	args->name = name->name;
 	args->namelen = name->len;
@@ -503,9 +497,6 @@ xfs_dir_removename(
 	XFS_STATS_INC(dp->i_mount, xs_dir_remove);
 
 	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
-	if (!args)
-		return -ENOMEM;
-
 	args->geo = dp->i_mount->m_dir_geo;
 	args->name = name->name;
 	args->namelen = name->len;
@@ -563,9 +554,6 @@ xfs_dir_replace(
 		return rval;
 
 	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
-	if (!args)
-		return -ENOMEM;
-
 	args->geo = dp->i_mount->m_dir_geo;
 	args->name = name->name;
 	args->namelen = name->len;
diff --git a/fs/xfs/libxfs/xfs_exchmaps.c b/fs/xfs/libxfs/xfs_exchmaps.c
index dcd0bd0b13b4..bd897676e38a 100644
--- a/fs/xfs/libxfs/xfs_exchmaps.c
+++ b/fs/xfs/libxfs/xfs_exchmaps.c
@@ -500,11 +500,6 @@ xfs_exchmaps_link_to_sf(
 	/* Read the current symlink target into a buffer. */
 	buf = kmalloc(ip->i_disk_size + 1,
 			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-	if (!buf) {
-		ASSERT(0);
-		return -ENOMEM;
-	}
-
 	error = xfs_symlink_remote_read(ip, buf);
 	if (error)
 		goto free;
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 3ce12fe1c307..5583139d7478 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -130,9 +130,6 @@ xfs_buf_alloc_kmem(
 	ASSERT(size < PAGE_SIZE);
 
 	bp->b_addr = kmalloc(size, gfp_mask | __GFP_NOFAIL);
-	if (!bp->b_addr)
-		return -ENOMEM;
-
 	/*
 	 * Slab guarantees that we get back naturally aligned allocations for
 	 * power of two sizes.  Keep this check as the canary in the coal mine
diff --git a/fs/xfs/xfs_mru_cache.c b/fs/xfs/xfs_mru_cache.c
index d61ec8cb126d..258c07da73e1 100644
--- a/fs/xfs/xfs_mru_cache.c
+++ b/fs/xfs/xfs_mru_cache.c
@@ -334,18 +334,10 @@ xfs_mru_cache_create(
 		return -EINVAL;
 
 	mru = kzalloc_obj(*mru, GFP_KERNEL | __GFP_NOFAIL);
-	if (!mru)
-		return -ENOMEM;
-
 	/* An extra list is needed to avoid reaping up to a grp_time early. */
 	mru->grp_count = grp_count + 1;
 	mru->lists = kzalloc(mru->grp_count * sizeof(*mru->lists),
 				GFP_KERNEL | __GFP_NOFAIL);
-	if (!mru->lists) {
-		kfree(mru);
-		return -ENOMEM;
-	}
-
 	for (grp = 0; grp < mru->grp_count; grp++)
 		INIT_LIST_HEAD(mru->lists + grp);
 
-- 
2.20.1


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

end of thread, other threads:[~2026-06-25  8:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-24 13:51 [PATCH] xfs: remove dead NULL check after __GFP_NOFAIL allocation Gou Hao
2026-06-25  8:42 ` Carlos Maiolino

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

all inboxes | Powered by JetHome®