From patchwork Thu Feb 5 11:53:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Gerlitz X-Patchwork-Id: 5784141 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C5AB99F302 for ; Thu, 5 Feb 2015 11:59:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F27B3202C8 for ; Thu, 5 Feb 2015 11:59:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0A27202AE for ; Thu, 5 Feb 2015 11:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757350AbbBEL7L (ORCPT ); Thu, 5 Feb 2015 06:59:11 -0500 Received: from mailp.voltaire.com ([193.47.165.129]:56966 "EHLO mellanox.co.il" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1757318AbbBEL7K (ORCPT ); Thu, 5 Feb 2015 06:59:10 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ogerlitz@mellanox.com) with ESMTPS (AES256-SHA encrypted); 5 Feb 2015 13:53:53 +0200 Received: from r-vnc04.mtr.labs.mlnx (r-vnc04.mtr.labs.mlnx [10.208.0.116]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id t15BrrMu028572; Thu, 5 Feb 2015 13:53:53 +0200 From: Or Gerlitz To: Roland Dreier Cc: linux-rdma@vger.kernel.org, Amir Vadai , Tal Alon , Sean Hefty , Majd Dibbiny , Or Gerlitz Subject: [PATCH RE-RESEND V2 for-next 2/5] IB/core: Fixes in ib_sa_add_one error flow Date: Thu, 5 Feb 2015 13:53:49 +0200 Message-Id: <1423137232-24587-3-git-send-email-ogerlitz@mellanox.com> X-Mailer: git-send-email 1.7.8.2 In-Reply-To: <1423137232-24587-1-git-send-email-ogerlitz@mellanox.com> References: <1423137232-24587-1-git-send-email-ogerlitz@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Majd Dibbiny 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 Signed-off-by: Or Gerlitz --- drivers/infiniband/core/sa_query.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) 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);