From patchwork Mon Oct 19 16:30:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 54801 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9JGUM1e018894 for ; Mon, 19 Oct 2009 16:30:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756089AbZJSQaQ (ORCPT ); Mon, 19 Oct 2009 12:30:16 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754877AbZJSQaQ (ORCPT ); Mon, 19 Oct 2009 12:30:16 -0400 Received: from mga11.intel.com ([192.55.52.93]:30477 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756864AbZJSQaO (ORCPT ); Mon, 19 Oct 2009 12:30:14 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 19 Oct 2009 09:16:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.44,586,1249282800"; d="scan'208";a="738034013" Received: from jf-86862487-dhcp-client.jf.intel.com (HELO msheftyMOBL2) ([134.134.36.135]) by fmsmga001.fm.intel.com with ESMTP; 19 Oct 2009 09:33:07 -0700 From: "Sean Hefty" To: "'Nir Naaman'" , "'linux-rdma'" References: Subject: [PATCH} librdmacm: fix race initializing library Date: Mon, 19 Oct 2009 09:30:16 -0700 Message-ID: <70A923FFB18B4139984C5F6D2DE67C51@amr.corp.intel.com> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcpKZqVfMBtuXnqzQHClkTwzh9IungGcbQAA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 In-Reply-To: Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/src/cma.c b/src/cma.c index 70dbe1c..87e73ac 100644 --- a/src/cma.c +++ b/src/cma.c @@ -205,30 +205,32 @@ static int ucma_init(void) struct ibv_device **dev_list = NULL; struct cma_device *cma_dev; struct ibv_device_attr attr; - int i, ret; + int i, ret, dev_cnt; pthread_mutex_lock(&mut); - if (cma_dev_cnt) - goto out; + if (cma_dev_cnt) { + pthread_mutex_unlock(&mut); + return 0; + } ret = check_abi_version(); if (ret) - goto err; + goto err1; - dev_list = ibv_get_device_list(&cma_dev_cnt); + dev_list = ibv_get_device_list(&dev_cnt); if (!dev_list) { printf("CMA: unable to get RDMA device list\n"); ret = -ENODEV; - goto err; + goto err1; } - cma_dev_array = malloc(sizeof *cma_dev * cma_dev_cnt); + cma_dev_array = malloc(sizeof *cma_dev * dev_cnt); if (!cma_dev_array) { ret = -ENOMEM; - goto err; + goto err2; } - for (i = 0; dev_list[i]; ++i) { + for (i = 0; dev_list[i];) { cma_dev = &cma_dev_array[i]; cma_dev->guid = ibv_get_device_guid(dev_list[i]); @@ -236,28 +238,34 @@ static int ucma_init(void) if (!cma_dev->verbs) { printf("CMA: unable to open RDMA device\n"); ret = -ENODEV; - goto err; + goto err3; } + i++; ret = ibv_query_device(cma_dev->verbs, &attr); if (ret) { printf("CMA: unable to query RDMA device\n"); - goto err; + goto err3; } cma_dev->port_cnt = attr.phys_port_cnt; cma_dev->max_initiator_depth = (uint8_t) attr.max_qp_init_rd_atom; cma_dev->max_responder_resources = (uint8_t) attr.max_qp_rd_atom; } -out: + + cma_dev_cnt = dev_cnt; pthread_mutex_unlock(&mut); ibv_free_device_list(dev_list); return 0; -err: - ucma_cleanup(); + +err3: + while (i--) + ibv_close_device(cma_dev_array[i].verbs); + free(cma_dev_array); +err2: + ibv_free_device_list(dev_list); +err1: pthread_mutex_unlock(&mut); - if (dev_list) - ibv_free_device_list(dev_list); return ret; }