summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-07-10 13:55:49 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-07-12 16:29:03 +0200
commit33d2f83e3f2c1fdabb365d25bed3aa630041cbc0 (patch)
tree64104b4a69d8a48f9069b43ccb130093ffc89aed /lib
parente9c3ceabd406c80d7b8c7813836b654b045fa0b3 (diff)
downloadlinux-stable-33d2f83e3f2c1fdabb365d25bed3aa630041cbc0.tar.gz
linux-stable-33d2f83e3f2c1fdabb365d25bed3aa630041cbc0.tar.bz2
linux-stable-33d2f83e3f2c1fdabb365d25bed3aa630041cbc0.zip
ida: don't use BUG_ON() for debugging
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 kfree(NULL)" 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 it. 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 free(alloc()); 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@gmail.com> Suggested-by: Matthew Wilcox <willy@infradead.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 6ff3b1c36e0a..82c24a417dc6 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -573,7 +573,9 @@ void ida_free(struct ida *ida, unsigned int id)
{
unsigned long flags;
- BUG_ON((int)id < 0);
+ if ((int)id < 0)
+ return;
+
xa_lock_irqsave(&ida->ida_rt, flags);
ida_remove(ida, id);
xa_unlock_irqrestore(&ida->ida_rt, flags);