aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:04:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:17 -0500
commit6a9200603d76de1f8029b83c041f8eef99877a65 (patch)
tree608661cabafc2f1124b1a47cecb8888f62ce1c55 /drivers/infiniband
parent5c213f86417b264b38b279def3363811c2be54f0 (diff)
IB/mlx4: convert to idr_alloc()
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jack Morgenstein <jackm@dev.mellanox.co.il> Cc: Or Gerlitz <ogerlitz@mellanox.com> Cc: Roland Dreier <roland@purestorage.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/hw/mlx4/cm.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/drivers/infiniband/hw/mlx4/cm.c b/drivers/infiniband/hw/mlx4/cm.c
index dbc99d41605c..80e59ed864b3 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)
203static struct id_map_entry * 203static struct id_map_entry *
204id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) 204id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
205{ 205{
206 int ret, id; 206 int ret;
207 static int next_id; 207 static int next_id;
208 struct id_map_entry *ent; 208 struct id_map_entry *ent;
209 struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov; 209 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)
220 ent->dev = to_mdev(ibdev); 220 ent->dev = to_mdev(ibdev);
221 INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout); 221 INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout);
222 222
223 do { 223 idr_preload(GFP_KERNEL);
224 spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); 224 spin_lock(&to_mdev(ibdev)->sriov.id_map_lock);
225 ret = idr_get_new_above(&sriov->pv_id_table, ent,
226 next_id, &id);
227 if (!ret) {
228 next_id = ((unsigned) id + 1) & MAX_IDR_MASK;
229 ent->pv_cm_id = (u32)id;
230 sl_id_map_add(ibdev, ent);
231 }
232 225
233 spin_unlock(&sriov->id_map_lock); 226 ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT);
234 } while (ret == -EAGAIN && idr_pre_get(&sriov->pv_id_table, GFP_KERNEL)); 227 if (ret >= 0) {
235 /*the function idr_get_new_above can return -ENOSPC, so don't insert in that case.*/ 228 next_id = ((unsigned)ret + 1) & MAX_IDR_MASK;
236 if (!ret) { 229 ent->pv_cm_id = (u32)ret;
237 spin_lock(&sriov->id_map_lock); 230 sl_id_map_add(ibdev, ent);
238 list_add_tail(&ent->list, &sriov->cm_list); 231 list_add_tail(&ent->list, &sriov->cm_list);
239 spin_unlock(&sriov->id_map_lock);
240 return ent;
241 } 232 }
233
234 spin_unlock(&sriov->id_map_lock);
235 idr_preload_end();
236
237 if (ret >= 0)
238 return ent;
239
242 /*error flow*/ 240 /*error flow*/
243 kfree(ent); 241 kfree(ent);
244 mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret); 242 mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret);