]> git.baikalelectronics.ru Git - kernel.git/commit
ida: don't use BUG_ON() for debugging
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 10 Jul 2022 20:55:49 +0000 (13:55 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 10 Jul 2022 20:55:49 +0000 (13:55 -0700)
commit0332fd6de649a1b37b42c7d6e72a767c03847da9
tree26f673f2da99cfa469462d35008249f9eada199e
parentde204bed5e07ed0ef44c4f8f268a20d95e8f2261
ida: don't use BUG_ON() for debugging

This is another old BUG_ON() that just shouldn't exist (see also commit
f12e3c91b836: "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: 690d96ed34f2 ("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>
lib/idr.c