mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations
@ 2026-07-23  8:18 Gou Hao
  2026-07-23  8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Gou Hao @ 2026-07-23  8:18 UTC (permalink / raw)
  To: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, mkchauras, sshegde, nilay, kees
  Cc: linuxppc-dev, linux-kernel, dri-devel, linux-rdma, linux-mm,
	gouhaojake, kernel

This is a code cleanup series that removes unreachable
NULL checks (and associated error handling) that follow allocations
using __GFP_NOFAIL, which guarantees non-NULL return.

Gou Hao (4):
  powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation
  drm: remove dead WARN_ON NULL check after GFP_NOFAIL allocation
  lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations
  RDMA/cxgb4: remove dead NULL checks after GFP_NOFAIL allocations

 arch/powerpc/sysdev/xive/common.c  |  3 ---
 drivers/gpu/drm/drm_modeset_lock.c |  4 ----
 drivers/infiniband/hw/cxgb4/mem.c  | 10 ++--------
 lib/test_hmm.c                     |  6 ------
 4 files changed, 2 insertions(+), 21 deletions(-)

-- 
2.20.1


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

* [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation
  2026-07-23  8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
@ 2026-07-23  8:18 ` Gou Hao
  2026-07-23  9:37   ` Mukesh Kumar Chaurasiya
  2026-07-23  8:18 ` [PATCH 2/4] drm: remove dead WARN_ON " Gou Hao
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Gou Hao @ 2026-07-23  8:18 UTC (permalink / raw)
  To: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, mkchauras, sshegde, nilay, kees
  Cc: linuxppc-dev, linux-kernel, dri-devel, linux-rdma, linux-mm,
	gouhaojake, kernel

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

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 arch/powerpc/sysdev/xive/common.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index dadd1f46ec93..79d7854259cb 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -1134,9 +1134,6 @@ static int __init xive_init_ipis(void)
 
 	xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids,
 				 GFP_KERNEL | __GFP_NOFAIL);
-	if (!xive_ipis)
-		goto out_free_domain;
-
 	for_each_node(node) {
 		struct xive_ipi_desc *xid = &xive_ipis[node];
 		struct xive_ipi_alloc_info info = { node };
-- 
2.20.1


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

* [PATCH 2/4] drm: remove dead WARN_ON NULL check after GFP_NOFAIL allocation
  2026-07-23  8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
  2026-07-23  8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
@ 2026-07-23  8:18 ` Gou Hao
  2026-07-23  8:18 ` [PATCH 3/4] lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
  2026-07-23  8:18 ` [PATCH 4/4] RDMA/cxgb4: " Gou Hao
  3 siblings, 0 replies; 6+ messages in thread
From: Gou Hao @ 2026-07-23  8:18 UTC (permalink / raw)
  To: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, mkchauras, sshegde, nilay, kees
  Cc: linuxppc-dev, linux-kernel, dri-devel, linux-rdma, linux-mm,
	gouhaojake, kernel

kzalloc_obj with the __GFP_NOFAIL flag will never return NULL, so the
subsequent WARN_ON(!ctx) is unreachable dead code. Remove it.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 drivers/gpu/drm/drm_modeset_lock.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c
index 2c806b0146d6..e14814c30d8c 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -149,11 +149,7 @@ void drm_modeset_lock_all(struct drm_device *dev)
 	int ret;
 
 	ctx = kzalloc_obj(*ctx, GFP_KERNEL | __GFP_NOFAIL);
-	if (WARN_ON(!ctx))
-		return;
-
 	mutex_lock(&config->mutex);
-
 	drm_modeset_acquire_init(ctx, 0);
 
 retry:
-- 
2.20.1


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

* [PATCH 3/4] lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations
  2026-07-23  8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
  2026-07-23  8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
  2026-07-23  8:18 ` [PATCH 2/4] drm: remove dead WARN_ON " Gou Hao
@ 2026-07-23  8:18 ` Gou Hao
  2026-07-23  8:18 ` [PATCH 4/4] RDMA/cxgb4: " Gou Hao
  3 siblings, 0 replies; 6+ messages in thread
From: Gou Hao @ 2026-07-23  8:18 UTC (permalink / raw)
  To: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, mkchauras, sshegde, nilay, kees
  Cc: linuxppc-dev, linux-kernel, dri-devel, linux-rdma, linux-mm,
	gouhaojake, kernel

kvcalloc with the __GFP_NOFAIL flag will never return NULL, so the
subsequent NULL checks are unreachable dead code. Remove them.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 lib/test_hmm.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index 9c59d1ceb5b5..d615e4e5fc44 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -1209,16 +1209,10 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror,
 	if (!mmget_not_zero(mm))
 		return -EINVAL;
 
-	ret = -ENOMEM;
 	src_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*src_pfns),
 			  GFP_KERNEL | __GFP_NOFAIL);
-	if (!src_pfns)
-		goto free_mem;
-
 	dst_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*dst_pfns),
 			  GFP_KERNEL | __GFP_NOFAIL);
-	if (!dst_pfns)
-		goto free_mem;
 
 	ret = 0;
 	mmap_read_lock(mm);
-- 
2.20.1


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

* [PATCH 4/4] RDMA/cxgb4: remove dead NULL checks after GFP_NOFAIL allocations
  2026-07-23  8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
                   ` (2 preceding siblings ...)
  2026-07-23  8:18 ` [PATCH 3/4] lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
@ 2026-07-23  8:18 ` Gou Hao
  3 siblings, 0 replies; 6+ messages in thread
From: Gou Hao @ 2026-07-23  8:18 UTC (permalink / raw)
  To: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, mkchauras, sshegde, nilay, kees
  Cc: linuxppc-dev, linux-kernel, dri-devel, linux-rdma, linux-mm,
	gouhaojake, kernel

alloc_skb() with the __GFP_NOFAIL flag will never return NULL,
so the subsequent NULL checks and error handling are unreachable
dead code. Remove them.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 drivers/infiniband/hw/cxgb4/mem.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index cd1b01014198..08631de17c0a 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -74,11 +74,8 @@ static int _c4iw_write_mem_dma_aligned(struct c4iw_rdev *rdev, u32 addr,
 		c4iw_init_wr_wait(wr_waitp);
 	wr_len = roundup(sizeof(*req) + sizeof(*sgl), 16);
 
-	if (!skb) {
+	if (!skb)
 		skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
-		if (!skb)
-			return -ENOMEM;
-	}
 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
 
 	req = __skb_put_zero(skb, wr_len);
@@ -134,11 +131,8 @@ static int _c4iw_write_mem_inline(struct c4iw_rdev *rdev, u32 addr, u32 len,
 					 roundup(copy_len, T4_ULPTX_MIN_IO),
 				 16);
 
-		if (!skb) {
+		if (!skb)
 			skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
-			if (!skb)
-				return -ENOMEM;
-		}
 		set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
 
 		req = __skb_put_zero(skb, wr_len);
-- 
2.20.1


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

* Re: [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation
  2026-07-23  8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
@ 2026-07-23  9:37   ` Mukesh Kumar Chaurasiya
  0 siblings, 0 replies; 6+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-07-23  9:37 UTC (permalink / raw)
  To: Gou Hao
  Cc: maddy, mpe, npiggin, chleroy, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, bharat, jgg, leon, akpm, ynorov,
	namcao, sshegde, nilay, kees, linuxppc-dev, linux-kernel,
	dri-devel, linux-rdma, linux-mm, gouhaojake, kernel

On Thu, Jul 23, 2026 at 04:18:10PM +0800, Gou Hao wrote:
> kzalloc_objs with the __GFP_NOFAIL flag will never return NULL, so the
> subsequent NULL check is unreachable dead code. Remove it.
> 
> Signed-off-by: Gou Hao <gouhao@uniontech.com>
> ---
>  arch/powerpc/sysdev/xive/common.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index dadd1f46ec93..79d7854259cb 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -1134,9 +1134,6 @@ static int __init xive_init_ipis(void)
>  
>  	xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids,
>  				 GFP_KERNEL | __GFP_NOFAIL);
> -	if (!xive_ipis)
> -		goto out_free_domain;
This will be an unused label after this.

Regards,
Mukesh
> -
>  	for_each_node(node) {
>  		struct xive_ipi_desc *xid = &xive_ipis[node];
>  		struct xive_ipi_alloc_info info = { node };
> -- 
> 2.20.1
> 

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

end of thread, other threads:[~2026-07-23  9:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-23  8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
2026-07-23  8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
2026-07-23  9:37   ` Mukesh Kumar Chaurasiya
2026-07-23  8:18 ` [PATCH 2/4] drm: remove dead WARN_ON " Gou Hao
2026-07-23  8:18 ` [PATCH 3/4] lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
2026-07-23  8:18 ` [PATCH 4/4] RDMA/cxgb4: " Gou Hao

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®