Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Gou Hao <gouhao@uniontech.com>
To: cem@kernel.org, djwong@kernel.org, hch@infradead.org, kees@kernel.org
Cc: linux-kernel@vger.kernel.org, gouhaojake@163.com,
	kernel@uniontech.com, linux-xfs@vger.kernel.org
Subject: [PATCH] xfs: remove dead NULL check after __GFP_NOFAIL allocation
Date: Wed, 24 Jun 2026 21:51:55 +0800	[thread overview]
Message-ID: <20260624135155.326834-1-gouhao@uniontech.com> (raw)

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


             reply	other threads:[~2026-06-24 13:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 13:51 Gou Hao [this message]
2026-06-25  8:42 ` [PATCH] xfs: remove dead NULL check after __GFP_NOFAIL allocation Carlos Maiolino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260624135155.326834-1-gouhao@uniontech.com \
    --to=gouhao@uniontech.com \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=gouhaojake@163.com \
    --cc=hch@infradead.org \
    --cc=kees@kernel.org \
    --cc=kernel@uniontech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox