public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL
@ 2026-03-03  3:33 hongao
  2026-03-03 14:41 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: hongao @ 2026-03-03  3:33 UTC (permalink / raw)
  To: cem, djwong, sandeen; +Cc: linux-xfs, linux-kernel, hongao

Remove redundant NULL check after kzalloc() with GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL.

Signed-off-by: hongao <hongao@uniontech.com>

diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 766631f0562e..f76dfc8f4e1a 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -2718,10 +2718,6 @@ xfs_dabuf_map(
 	if (nirecs > 1) {
 		map = kzalloc(nirecs * sizeof(struct xfs_buf_map),
 				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-		if (!map) {
-			error = -ENOMEM;
-			goto out_free_irecs;
-		}
 		*mapp = map;
 	}
 
-- 
2.51.0


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

* Re: [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL
  2026-03-03  3:33 [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL hongao
@ 2026-03-03 14:41 ` Christoph Hellwig
  2026-03-04  9:50 ` Carlos Maiolino
  2026-03-04 11:29 ` [PATCH v2] " hongao
  2 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-03-03 14:41 UTC (permalink / raw)
  To: hongao; +Cc: cem, djwong, sandeen, linux-xfs, linux-kernel

On Tue, Mar 03, 2026 at 11:33:32AM +0800, hongao wrote:
> Remove redundant NULL check after kzalloc() with GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL.

Looks good.  Might also be worth to switching to kcalloc while you're at
it.


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

* Re: [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL
  2026-03-03  3:33 [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL hongao
  2026-03-03 14:41 ` Christoph Hellwig
@ 2026-03-04  9:50 ` Carlos Maiolino
  2026-03-04 11:29 ` [PATCH v2] " hongao
  2 siblings, 0 replies; 6+ messages in thread
From: Carlos Maiolino @ 2026-03-04  9:50 UTC (permalink / raw)
  To: hongao; +Cc: djwong, sandeen, linux-xfs, linux-kernel

On Tue, Mar 03, 2026 at 11:33:32AM +0800, hongao wrote:
> Remove redundant NULL check after kzalloc() with GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL.
> 
> Signed-off-by: hongao <hongao@uniontech.com>
> 
> diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
> index 766631f0562e..f76dfc8f4e1a 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.c
> +++ b/fs/xfs/libxfs/xfs_da_btree.c
> @@ -2718,10 +2718,6 @@ xfs_dabuf_map(
>  	if (nirecs > 1) {
>  		map = kzalloc(nirecs * sizeof(struct xfs_buf_map),
>  				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
> -		if (!map) {
> -			error = -ENOMEM;
> -			goto out_free_irecs;
> -		}
>  		*mapp = map;
>  	}
>  

+1 for kcalloc.

feel free to add:
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> -- 
> 2.51.0
> 
> 

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

* [PATCH v2] xfs: Remove redundant NULL check after __GFP_NOFAIL
  2026-03-03  3:33 [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL hongao
  2026-03-03 14:41 ` Christoph Hellwig
  2026-03-04  9:50 ` Carlos Maiolino
@ 2026-03-04 11:29 ` hongao
  2026-03-04 13:20   ` Christoph Hellwig
  2026-03-05  9:47   ` Carlos Maiolino
  2 siblings, 2 replies; 6+ messages in thread
From: hongao @ 2026-03-04 11:29 UTC (permalink / raw)
  To: cem, linux-xfs; +Cc: djwong, sandeen, hch, linux-kernel, hongao

kzalloc() is called with __GFP_NOFAIL, so a NULL return is not expected.
Drop the redundant !map check in xfs_dabuf_map().
Also switch the nirecs-sized allocation to kcalloc().

Signed-off-by: hongao <hongao@uniontech.com>
---
 fs/xfs/libxfs/xfs_da_btree.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 766631f0562e..09d4c17b3e7b 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -2716,12 +2716,8 @@ xfs_dabuf_map(
 	 * larger one that needs to be free by the caller.
 	 */
 	if (nirecs > 1) {
-		map = kzalloc(nirecs * sizeof(struct xfs_buf_map),
-				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-		if (!map) {
-			error = -ENOMEM;
-			goto out_free_irecs;
-		}
+		map = kcalloc(nirecs, sizeof(struct xfs_buf_map),
+			      GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 		*mapp = map;
 	}
 
-- 
2.51.0


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

* Re: [PATCH v2] xfs: Remove redundant NULL check after __GFP_NOFAIL
  2026-03-04 11:29 ` [PATCH v2] " hongao
@ 2026-03-04 13:20   ` Christoph Hellwig
  2026-03-05  9:47   ` Carlos Maiolino
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-03-04 13:20 UTC (permalink / raw)
  To: hongao; +Cc: cem, linux-xfs, djwong, sandeen, hch, linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH v2] xfs: Remove redundant NULL check after __GFP_NOFAIL
  2026-03-04 11:29 ` [PATCH v2] " hongao
  2026-03-04 13:20   ` Christoph Hellwig
@ 2026-03-05  9:47   ` Carlos Maiolino
  1 sibling, 0 replies; 6+ messages in thread
From: Carlos Maiolino @ 2026-03-05  9:47 UTC (permalink / raw)
  To: linux-xfs, hongao; +Cc: djwong, sandeen, hch, linux-kernel

On Wed, 04 Mar 2026 19:29:14 +0800, hongao wrote:
> kzalloc() is called with __GFP_NOFAIL, so a NULL return is not expected.
> Drop the redundant !map check in xfs_dabuf_map().
> Also switch the nirecs-sized allocation to kcalloc().
> 
> 

Applied to for-next, thanks!

[1/1] xfs: Remove redundant NULL check after __GFP_NOFAIL
      commit: 281cb17787d4284a7790b9cbd80fded826ca7739

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>


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

end of thread, other threads:[~2026-03-05  9:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03  3:33 [PATCH] xfs: Remove redundant NULL check after __GFP_NOFAIL hongao
2026-03-03 14:41 ` Christoph Hellwig
2026-03-04  9:50 ` Carlos Maiolino
2026-03-04 11:29 ` [PATCH v2] " hongao
2026-03-04 13:20   ` Christoph Hellwig
2026-03-05  9:47   ` Carlos Maiolino

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