aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugh Dickins <hughd@google.com>2012-03-21 19:34:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 20:55:01 -0400
commit9f7de8275b46d9d11b1505adbfe6c2bb48df4741 (patch)
tree7495111b20585e6e4da20d1b46b7a3747903ce2a
parent0e79dedde951e981612ed4e6d74873d61d2a113b (diff)
idr: make idr_get_next() good for rcu_read_lock()
Make one small adjustment to idr_get_next(): take the height from the top layer (stable under RCU) instead of from the root (unprotected by RCU), as idr_find() does: so that it can be used with RCU locking. Copied comment on RCU locking from idr_find(). Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Li Zefan <lizf@cn.fujitsu.com> Cc: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/idr.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/idr.c b/lib/idr.c
index ed055b297c81..12499ba7967e 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -595,8 +595,10 @@ EXPORT_SYMBOL(idr_for_each);
595 * Returns pointer to registered object with id, which is next number to 595 * Returns pointer to registered object with id, which is next number to
596 * given id. After being looked up, *@nextidp will be updated for the next 596 * given id. After being looked up, *@nextidp will be updated for the next
597 * iteration. 597 * iteration.
598 *
599 * This function can be called under rcu_read_lock(), given that the leaf
600 * pointers lifetimes are correctly managed.
598 */ 601 */
599
600void *idr_get_next(struct idr *idp, int *nextidp) 602void *idr_get_next(struct idr *idp, int *nextidp)
601{ 603{
602 struct idr_layer *p, *pa[MAX_LEVEL]; 604 struct idr_layer *p, *pa[MAX_LEVEL];
@@ -605,11 +607,11 @@ void *idr_get_next(struct idr *idp, int *nextidp)
605 int n, max; 607 int n, max;
606 608
607 /* find first ent */ 609 /* find first ent */
608 n = idp->layers * IDR_BITS;
609 max = 1 << n;
610 p = rcu_dereference_raw(idp->top); 610 p = rcu_dereference_raw(idp->top);
611 if (!p) 611 if (!p)
612 return NULL; 612 return NULL;
613 n = (p->layer + 1) * IDR_BITS;
614 max = 1 << n;
613 615
614 while (id < max) { 616 while (id < max) {
615 while (n > 0 && p) { 617 while (n > 0 && p) {