aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:05:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:21 -0500
commit7175c61cc6b8e701441e79ef048c11ae97293463 (patch)
tree515c24958e871c550b3b7f0c2356b4909ba83d61 /lib
parent0ffc2a9c8072969253a20821c2c733a2cbb4c7c7 (diff)
idr: explain WARN_ON_ONCE() on negative IDs out-of-range ID
Until recently, when an negative ID is specified, idr functions used to ignore the sign bit and proceeded with the operation with the rest of bits, which is bizarre and error-prone. The behavior recently got changed so that negative IDs are treated as invalid but we're triggering WARN_ON_ONCE() on negative IDs just in case somebody was depending on the sign bit being ignored, so that those can be detected and fixed easily. We only need this for a while. Explain why WARN_ON_ONCE()s are there and that they can be removed later. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 1a30272066c6..73f4d53c02f3 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -569,6 +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 (WARN_ON_ONCE(id < 0)) 573 if (WARN_ON_ONCE(id < 0))
573 return; 574 return;
574 575
@@ -666,6 +667,14 @@ void *idr_find_slowpath(struct idr *idp, int id)
666 int n; 667 int n;
667 struct idr_layer *p; 668 struct idr_layer *p;
668 669
670 /*
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 */
669 if (WARN_ON_ONCE(id < 0)) 678 if (WARN_ON_ONCE(id < 0))
670 return NULL; 679 return NULL;
671 680
@@ -815,6 +824,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
815 int n; 824 int n;
816 struct idr_layer *p, *old_p; 825 struct idr_layer *p, *old_p;
817 826
827 /* see comment in idr_find_slowpath() */
818 if (WARN_ON_ONCE(id < 0)) 828 if (WARN_ON_ONCE(id < 0))
819 return ERR_PTR(-EINVAL); 829 return ERR_PTR(-EINVAL);
820 830