diff mbox series

[for-next,1/2] RDMA/core: Add dummy sg_offset pointer for ib_map_mr_sg() and ib_map_mr_sg_pi()

Message ID 20241105120841.860068-2-huangjunxian6@hisilicon.com (mailing list archive)
State New
Headers show
Series Small optimization for ib_map_mr_sg() and ib_map_mr_sg_pi() | expand

Commit Message

Junxian Huang Nov. 5, 2024, 12:08 p.m. UTC
ib_map_mr_sg() and ib_map_mr_sg_pi() allow ULPs to specify NULL as the
sg_offset/data_sg_offset/meta_sg_offset arguments. In these cases,
pass a dummy pointer to drivers so they don't have to add NULL pointer
checks.

Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
 drivers/infiniband/core/verbs.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 473ee0831307..27060554dde2 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -2670,6 +2670,9 @@  int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
 		    struct scatterlist *meta_sg, int meta_sg_nents,
 		    unsigned int *meta_sg_offset, unsigned int page_size)
 {
+	unsigned int data_dummy = 0;
+	unsigned int meta_dummy = 0;
+
 	if (unlikely(!mr->device->ops.map_mr_sg_pi ||
 		     WARN_ON_ONCE(mr->type != IB_MR_TYPE_INTEGRITY)))
 		return -EOPNOTSUPP;
@@ -2677,8 +2680,9 @@  int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
 	mr->page_size = page_size;
 
 	return mr->device->ops.map_mr_sg_pi(mr, data_sg, data_sg_nents,
-					    data_sg_offset, meta_sg,
-					    meta_sg_nents, meta_sg_offset);
+					    data_sg_offset ? : &data_dummy,
+					    meta_sg, meta_sg_nents,
+					    meta_sg_offset ? : &meta_dummy);
 }
 EXPORT_SYMBOL(ib_map_mr_sg_pi);
 
@@ -2711,12 +2715,14 @@  EXPORT_SYMBOL(ib_map_mr_sg_pi);
 int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
 		 unsigned int *sg_offset, unsigned int page_size)
 {
+	unsigned int dummy = 0;
+
 	if (unlikely(!mr->device->ops.map_mr_sg))
 		return -EOPNOTSUPP;
 
 	mr->page_size = page_size;
 
-	return mr->device->ops.map_mr_sg(mr, sg, sg_nents, sg_offset);
+	return mr->device->ops.map_mr_sg(mr, sg, sg_nents, sg_offset ? : &dummy);
 }
 EXPORT_SYMBOL(ib_map_mr_sg);