[PATCH 4.9 11/14] ida: dont use BUG_ON() for debugging
From: Greg Kroah-Hartman
Date: Mon Jul 11 2022 - 05:07:59 EST
From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
commit fc82bbf4dede758007763867d0282353c06d1121 upstream.
This is another old BUG_ON() that just shouldn't exist (see also commit
a382f8fee42c: "signal handling: don't use BUG_ON() for debugging").
In fact, as Matthew Wilcox points out, this condition shouldn't really
even result in a warning, since a negative id allocation result is just
a normal allocation failure:
"I wonder if we should even warn here -- sure, the caller is trying to
free something that wasn't allocated, but we don't warn for
and goes on to point out how that current error check is only causing
people to unnecessarily do their own index range checking before freeing
This was noted by Itay Iellin, because the bluetooth HCI socket cookie
code does *not* do that range checking, and ends up just freeing the
error case too, triggering the BUG_ON().
The HCI code requires CAP_NET_RAW, and seems to just result in an ugly
splat, but there really is no reason to BUG_ON() here, and we have
generally striven for allocation models where it's always ok to just do
even if the allocation were to fail for some random reason (usually
obviously that "random" reason being some resource limit).
Fixes: 88eca0207cf1 ("ida: simplified functions for id allocation")
Reported-by: Itay Iellin <ieitayie@xxxxxxxxx>
Suggested-by: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
lib/idr.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
@@ -1124,7 +1124,9 @@ void ida_simple_remove(struct ida *ida,
unsigned long flags;
- BUG_ON((int)id < 0);
+ if ((int)id < 0)