[for-next PATCH 2/5] RDMA/rxe: use iova_to_vaddr to transform iova for rxe_mr_copy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make the code more friendly and readable by using iova_to_vaddr()

This commit also remove the err1 label in rxe_mr_copy().

Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx>
---
 drivers/infiniband/sw/rxe/rxe_mr.c | 46 +++++++++---------------------
 1 file changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index f6366a635b92..cf3ce8d293b3 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -289,13 +289,6 @@ void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
 int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
 		enum rxe_mr_copy_dir dir)
 {
-	int			err;
-	int			bytes;
-	u8			*va;
-	struct rxe_map		**map;
-	struct rxe_phys_buf	*buf;
-	int			m;
-	int			i;
 	size_t			offset;
 
 	if (length == 0)
@@ -315,49 +308,36 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
 
 	WARN_ON_ONCE(!mr->map);
 
-	err = mr_check_range(mr, iova, length);
-	if (err) {
-		err = -EFAULT;
-		goto err1;
-	}
-
-	lookup_iova(mr, iova, &m, &i, &offset);
-
-	map = mr->map + m;
-	buf	= map[0]->buf + i;
+	if (mr_check_range(mr, iova, length))
+		return -EFAULT;
 
+	offset = (iova - mr->ibmr.iova + mr->offset) & mr->page_mask;
 	while (length > 0) {
-		u8 *src, *dest;
-
-		va	= (u8 *)(uintptr_t)buf->addr + offset;
-		src = (dir == RXE_TO_MR_OBJ) ? addr : va;
-		dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+		u8 *src, *dest, *va;
+		int bytes;
 
 		bytes	= mr->ibmr.page_size - offset;
 
 		if (bytes > length)
 			bytes = length;
 
+		va = iova_to_vaddr(mr, iova, bytes);
+		if (!va)
+			return -EFAULT;
+
+		src = (dir == RXE_TO_MR_OBJ) ? addr : va;
+		dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+
 		memcpy(dest, src, bytes);
 
 		length	-= bytes;
 		addr	+= bytes;
+		iova += bytes;
 
 		offset	= 0;
-		buf++;
-		i++;
-
-		if (i == RXE_BUF_PER_MAP) {
-			i = 0;
-			map++;
-			buf = map[0]->buf;
-		}
 	}
 
 	return 0;
-
-err1:
-	return err;
 }
 
 /* copy data in or out of a wqe, i.e. sg list
-- 
2.31.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux