Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 359382
b: refs/heads/master
c: e8c8d1b
h: refs/heads/master
v: v3
  • Loading branch information
Tejun Heo authored and Linus Torvalds committed Feb 28, 2013
1 parent 4f688b7 commit 65c3eed
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 326cf0f0f308933c10236280a322031f0097205d
refs/heads/master: e8c8d1bc063bc88cfa1356266027b5075d3a82d7
2 changes: 0 additions & 2 deletions trunk/drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,6 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adap)

if (adap->nr == -1) /* -1 means dynamically assign bus id */
return i2c_add_adapter(adap);
if (adap->nr & ~MAX_IDR_MASK)
return -EINVAL;

mutex_lock(&core_lock);
id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/infiniband/core/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)

id = idr_alloc(&cm.local_id_table, cm_id_priv, next_id, 0, GFP_NOWAIT);
if (id >= 0)
next_id = ((unsigned) id + 1) & MAX_IDR_MASK;
next_id = max(id + 1, 0);

spin_unlock_irqrestore(&cm.lock, flags);
idr_preload_end();
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/infiniband/hw/mlx4/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)

ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT);
if (ret >= 0) {
next_id = ((unsigned)ret + 1) & MAX_IDR_MASK;
next_id = max(ret + 1, 0);
ent->pv_cm_id = (u32)ret;
sl_id_map_add(ibdev, ent);
list_add_tail(&ent->list, &sriov->cm_list);
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ int get_anon_bdev(dev_t *p)
else if (error)
return -EAGAIN;

if ((dev & MAX_IDR_MASK) == (1 << MINORBITS)) {
if (dev == (1 << MINORBITS)) {
spin_lock(&unnamed_dev_lock);
ida_remove(&unnamed_dev_ida, dev);
if (unnamed_dev_start > dev)
Expand Down
10 changes: 0 additions & 10 deletions trunk/include/linux/idr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@
#define IDR_SIZE (1 << IDR_BITS)
#define IDR_MASK ((1 << IDR_BITS)-1)

#define MAX_IDR_SHIFT (sizeof(int)*8 - 1)
#define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
#define MAX_IDR_MASK (MAX_IDR_BIT - 1)

/* Leave the possibility of an incomplete final layer */
#define MAX_IDR_LEVEL ((MAX_IDR_SHIFT + IDR_BITS - 1) / IDR_BITS)

/* Number of id_layer structs to leave in free list */
#define MAX_IDR_FREE (MAX_IDR_LEVEL * 2)

struct idr_layer {
unsigned long bitmap; /* A zero bit means "space here" */
struct idr_layer __rcu *ary[1<<IDR_BITS];
Expand Down
24 changes: 17 additions & 7 deletions trunk/lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
#include <linux/percpu.h>
#include <linux/hardirq.h>

#define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
#define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)

/* Leave the possibility of an incomplete final layer */
#define MAX_IDR_LEVEL ((MAX_IDR_SHIFT + IDR_BITS - 1) / IDR_BITS)

/* Number of id_layer structs to leave in free list */
#define MAX_IDR_FREE (MAX_IDR_LEVEL * 2)

static struct kmem_cache *idr_layer_cache;
static DEFINE_PER_CPU(struct idr_layer *, idr_preload_head);
static DEFINE_PER_CPU(int, idr_preload_cnt);
Expand Down Expand Up @@ -542,8 +551,8 @@ void idr_remove(struct idr *idp, int id)
struct idr_layer *p;
struct idr_layer *to_free;

/* Mask off upper bits we don't use for the search. */
id &= MAX_IDR_MASK;
if (WARN_ON_ONCE(id < 0))
return;

sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
if (idp->top && idp->top->count == 1 && (idp->layers > 1) &&
Expand Down Expand Up @@ -650,14 +659,14 @@ void *idr_find(struct idr *idp, int id)
int n;
struct idr_layer *p;

if (WARN_ON_ONCE(id < 0))
return NULL;

p = rcu_dereference_raw(idp->top);
if (!p)
return NULL;
n = (p->layer+1) * IDR_BITS;

/* Mask off upper bits we don't use for the search. */
id &= MAX_IDR_MASK;

if (id > idr_max(p->layer + 1))
return NULL;
BUG_ON(n == 0);
Expand Down Expand Up @@ -799,14 +808,15 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
int n;
struct idr_layer *p, *old_p;

if (WARN_ON_ONCE(id < 0))
return ERR_PTR(-EINVAL);

p = idp->top;
if (!p)
return ERR_PTR(-EINVAL);

n = (p->layer+1) * IDR_BITS;

id &= MAX_IDR_MASK;

if (id >= (1 << n))
return ERR_PTR(-EINVAL);

Expand Down

0 comments on commit 65c3eed

Please sign in to comment.