Skip to content

Commit 8a7622b

Browse files
torvaldssmb49
authored andcommitted
ida: don't use BUG_ON() for debugging
BugLink: https://bugs.launchpad.net/bugs/1987451 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: 88eca02 ("ida: simplified functions for id allocation") Reported-by: Itay Iellin <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent fde282c commit 8a7622b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/idr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ void ida_free(struct ida *ida, unsigned int id)
491491
struct ida_bitmap *bitmap;
492492
unsigned long flags;
493493

494-
BUG_ON((int)id < 0);
494+
if ((int)id < 0)
495+
return;
495496

496497
xas_lock_irqsave(&xas, flags);
497498
bitmap = xas_load(&xas);

0 commit comments

Comments
 (0)