Skip to contentSkip to conversation

xfs: remove dead NULL check after __GFP_NOFAIL allocation

PATCH In review Gou Hao 2 participants 2 messages Jun 24 – Jun 25 XFS filesystem

lore
Share & tools
lore

Gou Hao

author
#0 lore raw

PATCH 1/1 xfs: remove dead NULL check after __GFP_NOFAIL allocation

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

---
 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(-)
fs/xfs/libxfs/xfs_dir2.c +0 -12
index 0c0402a29b6b..6009ec26843d 100644
@@ -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;
fs/xfs/libxfs/xfs_exchmaps.c +0 -5
index dcd0bd0b13b4..bd897676e38a 100644
@@ -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;
fs/xfs/xfs_buf.c +0 -3
index 3ce12fe1c307..5583139d7478 100644
@@ -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
fs/xfs/xfs_mru_cache.c +0 -8
index d61ec8cb126d..258c07da73e1 100644
@@ -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);
 
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Gou Hao

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

Looks fine.

Quoted 108 lines
---
 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(-)
fs/xfs/libxfs/xfs_dir2.c +0 -12
index 0c0402a29b6b..6009ec26843d 100644
@@ -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;
fs/xfs/libxfs/xfs_exchmaps.c +0 -5
index dcd0bd0b13b4..bd897676e38a 100644
@@ -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;
fs/xfs/xfs_buf.c +0 -3
index 3ce12fe1c307..5583139d7478 100644
@@ -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
fs/xfs/xfs_mru_cache.c +0 -8
index d61ec8cb126d..258c07da73e1 100644
@@ -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);
 
Signature · 1 line
2.20.1