Skip to contentSkip to conversation

RDMA/rxe: Fix a couple IS_ERR() vs NULL bugs

PATCH Applied Dan Carpenter 3 participants 4 messages Jun 25, 2025 – Jun 26, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/rxe: Fix a couple IS_ERR() vs NULL bugs

The lookup_mr() function returns NULL on error. It never returns error pointers.

Fixes 9284bc34c773 ("RDMA/rxe: Enable asynchronous prefetch for ODP MRs")
Fixes 3576b0df1588 ("RDMA/rxe: Implement synchronous prefetch for ODP MRs")
---
 drivers/infiniband/sw/rxe/rxe_odp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe_odp.c +5 -3
index 01a59d3f8ed4..f58e3ec6252f 100644
@@ -470,10 +470,10 @@ static int rxe_ib_prefetch_sg_list(struct ib_pd *ibpd,
 		mr = lookup_mr(pd, IB_ACCESS_LOCAL_WRITE,
 			       sg_list[i].lkey, RXE_LOOKUP_LOCAL);
 
-		if (IS_ERR(mr)) {
+		if (!mr) {
 			rxe_dbg_pd(pd, "mr with lkey %x not found\n",
 				   sg_list[i].lkey);
-			return PTR_ERR(mr);
+			return -EINVAL;
 		}
 
 		if (advice == IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE &&
@@ -535,8 +535,10 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd,
 		/* Takes a reference, which will be released in the queued work */
 		mr = lookup_mr(pd, IB_ACCESS_LOCAL_WRITE,
 			       sg_list[i].lkey, RXE_LOOKUP_LOCAL);
-		if (IS_ERR(mr))
+		if (!mr) {
+			mr = ERR_PTR(-EINVAL);
 			goto err;
+		}
 
 		work->frags[i].io_virt = sg_list[i].addr;
 		work->frags[i].length = sg_list[i].length;
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Dan Carpenter

The lookup_mr() function returns NULL on error. It never returns error pointers.

Yes, I agree with you. However, this commit is intended to fix an issue in the rdma-next tree. The corresponding repository is: https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git.

Therefore, the subject should be: [PATCH rdma-next]

This problem does not exist in the upstream Linux kernel.

Other than that, I have no issues with the commit.

Zhu Yanjun

Quoted 37 lines
Fixes 9284bc34c773 ("RDMA/rxe: Enable asynchronous prefetch for ODP MRs")
Fixes 3576b0df1588 ("RDMA/rxe: Implement synchronous prefetch for ODP MRs")
---
  drivers/infiniband/sw/rxe/rxe_odp.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe_odp.c +5 -3
index 01a59d3f8ed4..f58e3ec6252f 100644
@@ -470,10 +470,10 @@ static int rxe_ib_prefetch_sg_list(struct ib_pd *ibpd,
  		mr = lookup_mr(pd, IB_ACCESS_LOCAL_WRITE,
  			       sg_list[i].lkey, RXE_LOOKUP_LOCAL);
 
-		if (IS_ERR(mr)) {
+		if (!mr) {
  			rxe_dbg_pd(pd, "mr with lkey %x not found\n",
  				   sg_list[i].lkey);
-			return PTR_ERR(mr);
+			return -EINVAL;
  		}
 
  		if (advice == IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE &&
@@ -535,8 +535,10 @@ static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd,
  		/* Takes a reference, which will be released in the queued work */
  		mr = lookup_mr(pd, IB_ACCESS_LOCAL_WRITE,
  			       sg_list[i].lkey, RXE_LOOKUP_LOCAL);
-		if (IS_ERR(mr))
+		if (!mr) {
+			mr = ERR_PTR(-EINVAL);
  			goto err;
+		}
 
  		work->frags[i].io_virt = sg_list[i].addr;
  		work->frags[i].length = sg_list[i].length;
#2 lore raw
Quoted 10 lines · yanjun.zhu
Quoted 2 lines · Dan Carpenter

The lookup_mr() function returns NULL on error. It never returns error pointers.

Yes, I agree with you. However, this commit is intended to fix an issue in the rdma-next tree. The corresponding repository is:
https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git.

Therefore, the subject should be: [PATCH rdma-next]

Yeah... I moved to a different machine and copied an older version of my patching scripts. Normally, my scripts would put [PATCH next] in the subject.

regards,
dan carpenter