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>
This commit is contained in:
parent
5c213f8641
commit
6a9200603d
|
@ -203,7 +203,7 @@ static void sl_id_map_add(struct ib_device *ibdev, struct id_map_entry *new)
|
||||||
static struct id_map_entry *
|
static struct id_map_entry *
|
||||||
id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
|
id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
|
||||||
{
|
{
|
||||||
int ret, id;
|
int ret;
|
||||||
static int next_id;
|
static int next_id;
|
||||||
struct id_map_entry *ent;
|
struct id_map_entry *ent;
|
||||||
struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov;
|
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);
|
ent->dev = to_mdev(ibdev);
|
||||||
INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout);
|
INIT_DELAYED_WORK(&ent->timeout, id_map_ent_timeout);
|
||||||
|
|
||||||
do {
|
idr_preload(GFP_KERNEL);
|
||||||
spin_lock(&to_mdev(ibdev)->sriov.id_map_lock);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock(&sriov->id_map_lock);
|
ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT);
|
||||||
} while (ret == -EAGAIN && idr_pre_get(&sriov->pv_id_table, GFP_KERNEL));
|
if (ret >= 0) {
|
||||||
/*the function idr_get_new_above can return -ENOSPC, so don't insert in that case.*/
|
next_id = ((unsigned)ret + 1) & MAX_IDR_MASK;
|
||||||
if (!ret) {
|
ent->pv_cm_id = (u32)ret;
|
||||||
spin_lock(&sriov->id_map_lock);
|
sl_id_map_add(ibdev, ent);
|
||||||
list_add_tail(&ent->list, &sriov->cm_list);
|
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*/
|
/*error flow*/
|
||||||
kfree(ent);
|
kfree(ent);
|
||||||
mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret);
|
mlx4_ib_warn(ibdev, "No more space in the idr (err:0x%x)\n", ret);
|
||||||
|
|
Loading…
Reference in New Issue