aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:05:04 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:20 -0500
commite8c8d1bc063bc88cfa1356266027b5075d3a82d7 (patch)
treeb657e3a3aa9eb8499690bb2fc0cbd908cdd2a334 /drivers/infiniband
parent326cf0f0f308933c10236280a322031f0097205d (diff)
idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c
MAX_IDR_MASK is another weirdness in the idr interface. As idr covers whole positive integer range, it's defined as 0x7fffffff or INT_MAX. Its usage in idr_find(), idr_replace() and idr_remove() is bizarre. They basically mask off the sign bit and operate on the rest, so if the caller, by accident, passes in a negative number, the sign bit will be masked off and the remaining part will be used as if that was the input, which is worse than crashing. The constant is visible in idr.h and there are several users in the kernel. * drivers/i2c/i2c-core.c:i2c_add_numbered_adapter() Basically used to test if adap->nr is a negative number which isn't -1 and returns -EINVAL if so. idr_alloc() already has negative @start checking (w/ WARN_ON_ONCE), so this can go away. * drivers/infiniband/core/cm.c:cm_alloc_id() drivers/infiniband/hw/mlx4/cm.c:id_map_alloc() Used to wrap cyclic @start. Can be replaced with max(next, 0). Note that this type of cyclic allocation using idr is buggy. These are prone to spurious -ENOSPC failure after the first wraparound. * fs/super.c:get_anon_bdev() The ID allocated from ida is masked off before being tested whether it's inside valid range. ida allocated ID can never be a negative number and the masking is unnecessary. Update idr_*() functions to fail with -EINVAL when negative @id is specified and update other MAX_IDR_MASK users as described above. This leaves MAX_IDR_MASK without any user, remove it and relocate other MAX_IDR_* constants to lib/idr.c. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jean Delvare <khali@linux-fr.org> Cc: Roland Dreier <roland@kernel.org> Cc: Sean Hefty <sean.hefty@intel.com> Cc: Hal Rosenstock <hal.rosenstock@gmail.com> Cc: "Marciniszyn, Mike" <mike.marciniszyn@intel.com> Cc: Jack Morgenstein <jackm@dev.mellanox.co.il> Cc: Or Gerlitz <ogerlitz@mellanox.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Acked-by: Wolfram Sang <wolfram@the-dreams.de> 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/core/cm.c2
-rw-r--r--drivers/infiniband/hw/mlx4/cm.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 98281fe5ea4b..784b97cb05b0 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -390,7 +390,7 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
390 390
391 id = idr_alloc(&cm.local_id_table, cm_id_priv, next_id, 0, GFP_NOWAIT); 391 id = idr_alloc(&cm.local_id_table, cm_id_priv, next_id, 0, GFP_NOWAIT);
392 if (id >= 0) 392 if (id >= 0)
393 next_id = ((unsigned) id + 1) & MAX_IDR_MASK; 393 next_id = max(id + 1, 0);
394 394
395 spin_unlock_irqrestore(&cm.lock, flags); 395 spin_unlock_irqrestore(&cm.lock, flags);
396 idr_preload_end(); 396 idr_preload_end();
diff --git a/drivers/infiniband/hw/mlx4/cm.c b/drivers/infiniband/hw/mlx4/cm.c
index 80e59ed864b3..e0d79b2395e4 100644
--- a/drivers/infiniband/hw/mlx4/cm.c
+++ b/drivers/infiniband/hw/mlx4/cm.c
@@ -225,7 +225,7 @@ id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
225 225
226 ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT); 226 ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT);
227 if (ret >= 0) { 227 if (ret >= 0) {
228 next_id = ((unsigned)ret + 1) & MAX_IDR_MASK; 228 next_id = max(ret + 1, 0);
229 ent->pv_cm_id = (u32)ret; 229 ent->pv_cm_id = (u32)ret;
230 sl_id_map_add(ibdev, ent); 230 sl_id_map_add(ibdev, ent);
231 list_add_tail(&ent->list, &sriov->cm_list); 231 list_add_tail(&ent->list, &sriov->cm_list);