[ofa-general] [PATCH] core: check optional verbs before using them

Dotan Barak dotanb at dev.mellanox.co.il
Mon Mar 31 07:50:02 PDT 2008


Check that all optional verbs are implemented in the device
before using them.

Signed-off-by: Dotan Barak <dotanb at dev.mellanox.co.il>

---

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 86ed8af..d0324d5 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -248,7 +248,9 @@ int ib_modify_srq(struct ib_srq *srq,
 		  struct ib_srq_attr *srq_attr,
 		  enum ib_srq_attr_mask srq_attr_mask)
 {
-	return srq->device->modify_srq(srq, srq_attr, srq_attr_mask, NULL);
+	return srq->device->modify_srq ?
+		srq->device->modify_srq(srq, srq_attr, srq_attr_mask, NULL) :
+		-ENOSYS;
 }
 EXPORT_SYMBOL(ib_modify_srq);
 
@@ -265,6 +267,9 @@ int ib_destroy_srq(struct ib_srq *srq)
 	struct ib_pd *pd;
 	int ret;
 
+	if (!srq->device->destroy_srq)
+		return -ENOSYS;
+
 	if (atomic_read(&srq->usecnt))
 		return -EBUSY;
 
@@ -672,6 +677,9 @@ struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
 {
 	struct ib_mr *mr;
 
+	if (!pd->device->reg_phys_mr)
+		return ERR_PTR(-ENOSYS);
+
 	mr = pd->device->reg_phys_mr(pd, phys_buf_array, num_phys_buf,
 				     mr_access_flags, iova_start);
 
@@ -769,6 +777,9 @@ int ib_dealloc_mw(struct ib_mw *mw)
 	struct ib_pd *pd;
 	int ret;
 
+	if (!mw->device->dealloc_mw)
+		return -ENOSYS;
+
 	pd = mw->pd;
 	ret = mw->device->dealloc_mw(mw);
 	if (!ret)
@@ -817,6 +828,9 @@ int ib_dealloc_fmr(struct ib_fmr *fmr)
 	struct ib_pd *pd;
 	int ret;
 
+	if (!fmr->device->dealloc_fmr)
+		return -ENOSYS;
+
 	pd = fmr->pd;
 	ret = fmr->device->dealloc_fmr(fmr);
 	if (!ret)



More information about the general mailing list