diff mbox series

[for-next,3/5] RDMA/rxe: iova_to_vaddr cleanup

Message ID 1668141030-2-4-git-send-email-lizhijian@fujitsu.com (mailing list archive)
State Changes Requested
Delegated to: Jason Gunthorpe
Headers show
Series iova_to_vaddr refactor | expand

Commit Message

Zhijian Li (Fujitsu) Nov. 11, 2022, 4:30 a.m. UTC
No functional change, do cleanup for refactoring it easily later.

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 drivers/infiniband/sw/rxe/rxe_mr.c | 37 ++++++++++++++----------------
 1 file changed, 17 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index cf3ce8d293b3..a4e786b657b7 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -246,41 +246,38 @@  static void lookup_iova(struct rxe_mr *mr, u64 iova, int *m_out, int *n_out,
 	}
 }
 
-void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
+static void *__iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
 {
 	size_t offset;
 	int m, n;
-	void *addr;
 
+	lookup_iova(mr, iova, &m, &n, &offset);
+
+	if (offset + length > mr->ibmr.page_size) {
+		pr_warn("crosses page boundary\n");
+		return NULL;
+	}
+
+	return (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset;
+}
+
+void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
+{
 	if (mr->state != RXE_MR_STATE_VALID) {
 		pr_warn("mr not in valid state\n");
-		addr = NULL;
-		goto out;
+		return NULL;
 	}
 
 	if (!mr->map) {
-		addr = (void *)(uintptr_t)iova;
-		goto out;
+		return (void *)(uintptr_t)iova;
 	}
 
 	if (mr_check_range(mr, iova, length)) {
 		pr_warn("range violation\n");
-		addr = NULL;
-		goto out;
-	}
-
-	lookup_iova(mr, iova, &m, &n, &offset);
-
-	if (offset + length > mr->ibmr.page_size) {
-		pr_warn("crosses page boundary\n");
-		addr = NULL;
-		goto out;
+		return NULL;
 	}
 
-	addr = (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset;
-
-out:
-	return addr;
+	return __iova_to_vaddr(mr, iova, length);
 }
 
 /* copy data from a range (vaddr, vaddr+length-1) to or from