Re: [PATCH 2/2] ring-buffer: replace most bug ons with warn on and disable buffer

Ingo Molnar
2008-11-11T09:09:47Z

* Steven Rostedt <rostedt@goodmis.org> wrote:

> +#define RB_WARN_ON_RET_INT(buffer, cond) \
> + do { \
> + if (unlikely(cond)) { \
> + atomic_inc(&buffer->record_disabled); \
> + WARN_ON(1); \
> return -1; \
> } \

btw., the _RET() methods are rather ugly as they include an implicit
code flow change (a 'return' statement).

Please change it to a more readable form that preserves the code flow,
something like:

if (RB_WARN_ON(buffer, cond))
return -1;

See kernel/lockdep.c about how to do this cleanly: introduce a
_single_ global "oh, we are broken" flag which is increased once and
never decreased again.

In the case of lockdep that's the debug_locks flag. It's used in
various code-flow-preserving forms of debug checks:

...
if (DEBUG_LOCKS_WARN_ON(depth >= 20))
return;
...
if (!debug_locks_off_graph_unlock())
return NULL;
...
if (!debug_locks_off_graph_unlock())
return 0;
...
if (!__raw_spin_is_locked(&lockdep_lock))
return DEBUG_LOCKS_WARN_ON(1);

etc.

Ingo