From: Willy Tarreau Date: Mon, 10 Aug 2026 14:50:39 +0000 (+0200) Subject: MINOR: debug: check the match count in __BUG_ON_ONCE() and not in complain() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c627ed7af386d4e90628f20f5dacfc903863da7d;p=thirdparty%2Fhaproxy.git MINOR: debug: check the match count in __BUG_ON_ONCE() and not in complain() The fix in commit 7a78d6c600 ("BUG/MINOR: debug: only dump the trace once in __BUG_ON_ONCE()") warned that it's not strictly atomic, but we could do better and take this opportunity for cleaning the code: use a fetch-add in __BUG_ON_ONCE() and pass NULL to complain(), which thus no longer has any call place requiring it to check a counter. This only very slightly inflates the code (~138B) since each BUG_ON_ONCE() now has to load 1, xadd(), check the return value instead of leaving it to complain(), but this is totally marginal compared to the benefits. This can even be backported where the fix above is backported if needed. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 34f043dd4..0353a7db6 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -437,9 +437,9 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S msg ="\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__ "\n"; \ else \ msg = "\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n"; \ - complain(&__match_count_##line, msg, crash); \ - if (_HA_ATOMIC_LOAD(&__match_count_##line) > 1) \ + if (_HA_ATOMIC_FETCH_ADD(&__match_count_##line, 1)) \ break; \ + complain(NULL, msg, crash); \ if (crash & 1) \ ABORT_NOW(); \ else \