[openib-general] [PATCH] If addr_handler() got error, do not set state as OK

Krishna Kumar krkumar2 at in.ibm.com
Mon Oct 16 21:39:20 PDT 2006


If addr_handler() got invoked with an error status,
do not set id_priv->state to success followed by
resettting it to the old value (redundant code).
Also encapsulate some common code.

Signed-off-by: Krishna Kumar <krkumar2 at in.ibm.com>
--------
diff -ruNp org/drivers/infiniband/core/cma.c new/drivers/infiniband/core/cma.c
--- org/drivers/infiniband/core/cma.c	2006-10-10 15:45:27.000000000 +0530
+++ new/drivers/infiniband/core/cma.c	2006-10-10 15:59:53.000000000 +0530
@@ -1515,6 +1515,8 @@ static void addr_handler(int status, str
 {
 	struct rdma_id_private *id_priv = context;
 	enum rdma_cm_event_type event;
+	int did_comp_exch = 0;
+	int destroy = 0;
 
 	atomic_inc(&id_priv->dev_remove);
 
@@ -1523,17 +1525,20 @@ static void addr_handler(int status, str
 	 * we're trying to acquire it.
 	 */
 	mutex_lock(&lock);
-	if (!cma_comp_exch(id_priv, CMA_ADDR_QUERY, CMA_ADDR_RESOLVED)) {
-		mutex_unlock(&lock);
-		goto out;
+	if (!status) {
+		if (!cma_comp_exch(id_priv, CMA_ADDR_QUERY,
+				   CMA_ADDR_RESOLVED)) {
+			mutex_unlock(&lock);
+			goto out;
+		}
+		did_comp_exch = 1;
+		if (!id_priv->cma_dev)
+			status = cma_acquire_dev(id_priv);
 	}
-
-	if (!status && !id_priv->cma_dev)
-		status = cma_acquire_dev(id_priv);
 	mutex_unlock(&lock);
-
 	if (status) {
-		if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ADDR_BOUND))
+		if (did_comp_exch && !cma_comp_exch(id_priv, CMA_ADDR_RESOLVED,
+						    CMA_ADDR_BOUND))
 			goto out;
 		event = RDMA_CM_EVENT_ADDR_ERROR;
 	} else {
@@ -1544,14 +1549,13 @@ static void addr_handler(int status, str
 
 	if (cma_notify_user(id_priv, event, status, NULL, 0)) {
 		cma_exch(id_priv, CMA_DESTROYING);
-		cma_release_remove(id_priv);
-		cma_deref_id(id_priv);
-		rdma_destroy_id(&id_priv->id);
-		return;
+		destroy = 1;
 	}
 out:
 	cma_release_remove(id_priv);
 	cma_deref_id(id_priv);
+	if (destroy)
+		rdma_destroy_id(&id_priv->id);
 }
 
 static int cma_resolve_loopback(struct rdma_id_private *id_priv)




More information about the general mailing list