diff mbox

[RE-RESEND,V2,for-next,2/5] IB/core: Fixes in ib_sa_add_one error flow

Message ID 1423137232-24587-3-git-send-email-ogerlitz@mellanox.com (mailing list archive)
State Rejected
Headers show

Commit Message

Or Gerlitz Feb. 5, 2015, 11:53 a.m. UTC
From: Majd Dibbiny <majd@mellanox.com>

Fixed off-by-one bug, we need to decrement the port number only after we
released the resources to the current port.

Call ib_unregister_mad_agent only for cases where ib_register_mad_agent succeeded.

Separate the ib_register_event_handler() call error flow from the loop error
flow. If the call to ib_register_event_handler fails, the client data must be
reset to NULL, (in case at some point ib_register_event_handler() is modified so
that it may return a non-zero (error) value).

Signed-off-by: Majd Dibbiny <majd@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
---
 drivers/infiniband/core/sa_query.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index c38f030..80461af 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -1202,7 +1202,7 @@  static void ib_sa_add_one(struct ib_device *device)
 
 	INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
 	if (ib_register_event_handler(&sa_dev->event_handler))
-		goto err;
+		goto reg_err;
 
 	for (i = 0; i <= e - s; ++i)
 		if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND)
@@ -1210,9 +1210,13 @@  static void ib_sa_add_one(struct ib_device *device)
 
 	return;
 
+reg_err:
+	ib_set_client_data(device, &sa_client, NULL);
+	i = e - s;
 err:
-	while (--i >= 0)
-		if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND)
+	for (; i >= 0; --i)
+		if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND &&
+		    !IS_ERR(sa_dev->port[i].agent))
 			ib_unregister_mad_agent(sa_dev->port[i].agent);
 
 	kfree(sa_dev);