From patchwork Wed Feb 6 19:40:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 2107251 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9229F3FCFC for ; Wed, 6 Feb 2013 20:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758234Ab3BFUAa (ORCPT ); Wed, 6 Feb 2013 15:00:30 -0500 Received: from mail-ia0-f181.google.com ([209.85.210.181]:51307 "EHLO mail-ia0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758215Ab3BFTuh (ORCPT ); Wed, 6 Feb 2013 14:50:37 -0500 Received: by mail-ia0-f181.google.com with SMTP id k25so2066474iah.12 for ; Wed, 06 Feb 2013 11:50:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=clzJjNr05sRcmQwgYIQCW5zOUqL9LvRs1lruHeTOO4I=; b=P1D892qg4ya9JxRXiKlTy1+Bw7sp1GltoeBCCDy0Ih/In9fLdTzZGRxjCoWjWpYQo+ vXoUvbSpq4AzDuq1VwJZJwVCN1cbyBCbW9jNmAnvBX2Lq7tPdkGQ1MZyu99eZPN2FDPQ p/CTLAWPN5I3p0D+54Zulg2fToLTJTyOXty1uMEJw2BczhS6XERKeqigwTG6rQ11oFyC ymQGP9CHpBhciq6TEoJYedmTQDOURvrjIrfH+QCZPAsCeV09OYRIiM3mDzWxJaa4MRi9 0KIUJrDZyerV56HmilWFg8xYQHw1TpNS3NQz/KzSomZ632m/tuscY7HWDeQYzlhFv3AK PJPw== X-Received: by 10.50.7.204 with SMTP id l12mr8771948iga.103.1360180236282; Wed, 06 Feb 2013 11:50:36 -0800 (PST) Received: from htj.dyndns.org (c-69-181-251-227.hsd1.ca.comcast.net. [69.181.251.227]) by mx.google.com with ESMTPS id l5sm39989590pax.10.2013.02.06.11.50.34 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 11:50:35 -0800 (PST) From: Tejun Heo To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Tejun Heo , Jack Morgenstein , Or Gerlitz , Roland Dreier , linux-rdma@vger.kernel.org Subject: [PATCH 44/77] IB/mlx4: convert to idr_alloc() Date: Wed, 6 Feb 2013 11:40:16 -0800 Message-Id: <1360179649-22465-45-git-send-email-tj@kernel.org> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1360179649-22465-1-git-send-email-tj@kernel.org> References: <1360179649-22465-1-git-send-email-tj@kernel.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Convert to the much saner new idr interface. Only compile tested. Signed-off-by: Tejun Heo Cc: Jack Morgenstein Cc: Or Gerlitz Cc: Roland Dreier Cc: linux-rdma@vger.kernel.org --- drivers/infiniband/hw/mlx4/cm.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/cm.c b/drivers/infiniband/hw/mlx4/cm.c index dbc99d4..80e59ed 100644 --- a/drivers/infiniband/hw/mlx4/cm.c +++ b/drivers/infiniband/hw/mlx4/cm.c @@ -203,7 +203,7 @@ static void sl_id_map_add(struct ib_device *ibdev, struct id_map_entry *new) static struct id_map_entry * id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) { - int ret, id; + int ret; static int next_id; struct id_map_entry *ent; struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov; @@ -220,25 +220,23 @@ id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) ent->dev = to_mdev(ibdev); INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout); - do { - spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); - ret = idr_get_new_above(&sriov->pv_id_table, ent, - next_id, &id); - if (!ret) { - next_id = ((unsigned) id + 1) & MAX_IDR_MASK; - ent->pv_cm_id = (u32)id; - sl_id_map_add(ibdev, ent); - } + idr_preload(GFP_KERNEL); + spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); - spin_unlock(&sriov->id_map_lock); - } while (ret == -EAGAIN && idr_pre_get(&sriov->pv_id_table, GFP_KERNEL)); - /*the function idr_get_new_above can return -ENOSPC, so don't insert in that case.*/ - if (!ret) { - spin_lock(&sriov->id_map_lock); + ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT); + if (ret >= 0) { + next_id = ((unsigned)ret + 1) & MAX_IDR_MASK; + ent->pv_cm_id = (u32)ret; + sl_id_map_add(ibdev, ent); list_add_tail(&ent->list, &sriov->cm_list); - spin_unlock(&sriov->id_map_lock); - return ent; } + + spin_unlock(&sriov->id_map_lock); + idr_preload_end(); + + if (ret >= 0) + return ent; + /*error flow*/ kfree(ent); mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret);