Commit 2e1c9b28 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

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: default avatarTejun Heo <tj@kernel.org>
Reported-by: <markus@trippelsdorf.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7880639c
...@@ -569,8 +569,7 @@ void idr_remove(struct idr *idp, int id) ...@@ -569,8 +569,7 @@ void idr_remove(struct idr *idp, int id)
struct idr_layer *p; struct idr_layer *p;
struct idr_layer *to_free; struct idr_layer *to_free;
/* see comment in idr_find_slowpath() */ if (id < 0)
if (WARN_ON_ONCE(id < 0))
return; return;
sub_remove(idp, (idp->layers - 1) * IDR_BITS, id); sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
...@@ -667,15 +666,7 @@ void *idr_find_slowpath(struct idr *idp, int id) ...@@ -667,15 +666,7 @@ void *idr_find_slowpath(struct idr *idp, int id)
int n; int n;
struct idr_layer *p; struct idr_layer *p;
/* if (id < 0)
* If @id is negative, idr_find() used to ignore the sign bit and
* performed lookup with the rest of bits, which is weird and can
* lead to very obscure bugs. We're now returning NULL for all
* negative IDs but just in case somebody was depending on the sign
* bit being ignored, let's trigger WARN_ON_ONCE() so that they can
* be detected and fixed. WARN_ON_ONCE() can later be removed.
*/
if (WARN_ON_ONCE(id < 0))
return NULL; return NULL;
p = rcu_dereference_raw(idp->top); p = rcu_dereference_raw(idp->top);
...@@ -824,8 +815,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id) ...@@ -824,8 +815,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
int n; int n;
struct idr_layer *p, *old_p; struct idr_layer *p, *old_p;
/* see comment in idr_find_slowpath() */ if (id < 0)
if (WARN_ON_ONCE(id < 0))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
p = idp->top; p = idp->top;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment