Re: [PATCH v2 2/6] usage.c: add a non-fatal bug() function to go with BUG()
- From
Glen Choo <chooglen@google.com>
- Date
- May 31, 2022, 18:18 UTC
- Message-ID
- <kl6lr149efbf.fsf@chooglen-macbookpro.roam.corp.google.com>
- In-Reply-To
- <patch-v2-2.6-2d0527f86dc-20220531T164806Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 9 quoted lines
> +static void check_bug_if_BUG(void)
> +{
> + if (!bug_called_must_BUG)
> + return;
> +
> + /* BUG_vfl() calls exit(), which calls us again */
> + bug_called_must_BUG = 0;
> + BUG("on exit(): had bug() call(s) in this process without explicit BUG_if_bug()");
> +}Hm thinking out loud here, what if we set bug_called_must_BUG = 0 inside of BUG()? Then we'd be guaranteed that BUG() will never infinitely recurse.
Another benefit is that we can invoke bug() and follow up with BUG() to unconditionally exit without a bogus warning "had bug() call(s) without explicit BUG_if_bug()". This pattern could be useful for 6/6 [1], where we no longer exit after printing the "BUG:" messages.
Just an idea :)
[1] https://lore.kernel.org/git/patch-v2-6.6-cbbe0276966-20220531T164806Z-avarab@gmail.com