aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-03-08 15:43:30 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-03-08 18:05:34 -0500
commit2e1c9b2867656ff9a469d23e1dfe90cf77ec0c72 (patch)
treeb1f8c8a5fde730b2e3c71239e125e451df039fa5
parent7880639c3e4fde5953ff243ee52204ddc5af641b (diff)
idr: remove WARN_ON_ONCE() on negative IDs
idr_find(), idr_remove() and idr_replace() used to silently ignore the sign bit and perform lookup with the rest of the bits. The weird behavior has been changed such that negative IDs are treated as invalid. As the behavior change was subtle, WARN_ON_ONCE() was added in the hope of determining who's calling idr functions with negative IDs so that they can be examined for problems. Up until now, all two reported cases are ID number coming directly from userland and getting fed into idr_find() and the warnings seem to cause more problems than being helpful. Drop the WARN_ON_ONCE()s. Signed-off-by: Tejun Heo <tj@kernel.org> Reported-by: <markus@trippelsdorf.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/idr.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 73f4d53c02f3..00739aaf95a2 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -569,8 +569,7 @@ void idr_remove(struct idr *idp, int id)
569 struct idr_layer *p; 569 struct idr_layer *p;
570 struct idr_layer *to_free; 570 struct idr_layer *to_free;
571 571
572 /* see comment in idr_find_slowpath() */ 572 if (id < 0)
573 if (WARN_ON_ONCE(id < 0))
574 return; 573 return;
575 574
576 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id); 575 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
@@ -667,15 +666,7 @@ void *idr_find_slowpath(struct idr *idp, int id)
667 int n; 666 int n;
668 struct idr_layer *p; 667 struct idr_layer *p;
669 668
670 /* 669 if (id < 0)
671 * If @id is negative, idr_find() used to ignore the sign bit and
672 * performed lookup with the rest of bits, which is weird and can
673 * lead to very obscure bugs. We're now returning NULL for all
674 * negative IDs but just in case somebody was depending on the sign
675 * bit being ignored, let's trigger WARN_ON_ONCE() so that they can
676 * be detected and fixed. WARN_ON_ONCE() can later be removed.
677 */
678 if (WARN_ON_ONCE(id < 0))
679 return NULL; 670 return NULL;
680 671
681 p = rcu_dereference_raw(idp->top); 672 p = rcu_dereference_raw(idp->top);
@@ -824,8 +815,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
824 int n; 815 int n;
825 struct idr_layer *p, *old_p; 816 struct idr_layer *p, *old_p;
826 817
827 /* see comment in idr_find_slowpath() */ 818 if (id < 0)
828 if (WARN_ON_ONCE(id < 0))
829 return ERR_PTR(-EINVAL); 819 return ERR_PTR(-EINVAL);
830 820
831 p = idp->top; 821 p = idp->top;