ALSA: Make snd_BUG_ON() always evaluate and return the conditional expression
Having snd_BUG_ON() only evaluate its conditional when CONFIG_SND_DEBUG is set leads to frequent bugs, since other similar macros in the kernel have different behavior. Let's make snd_BUG_ON() act like those macros so it will stop being accidentally misused. Signed-off-by: Christine Spang <christine.spang@oracle.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
8ba955cef3
commit
d5702162f8
|
@ -6164,14 +6164,12 @@ struct _snd_pcm_runtime {
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The macro takes an conditional expression to evaluate.
|
The macro takes an conditional expression to evaluate.
|
||||||
When <constant>CONFIG_SND_DEBUG</constant>, is set, the
|
When <constant>CONFIG_SND_DEBUG</constant>, is set, if the
|
||||||
expression is actually evaluated. If it's non-zero, it shows
|
expression is non-zero, it shows the warning message such as
|
||||||
the warning message such as
|
|
||||||
<computeroutput>BUG? (xxx)</computeroutput>
|
<computeroutput>BUG? (xxx)</computeroutput>
|
||||||
normally followed by stack trace. It returns the evaluated
|
normally followed by stack trace.
|
||||||
value.
|
|
||||||
When no <constant>CONFIG_SND_DEBUG</constant> is set, this
|
In both cases it returns the evaluated value.
|
||||||
macro always returns zero.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -379,18 +379,10 @@ void __snd_printk(unsigned int level, const char *file, int line,
|
||||||
* snd_BUG_ON - debugging check macro
|
* snd_BUG_ON - debugging check macro
|
||||||
* @cond: condition to evaluate
|
* @cond: condition to evaluate
|
||||||
*
|
*
|
||||||
* When CONFIG_SND_DEBUG is set, this macro evaluates the given condition,
|
* Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
|
||||||
* and call WARN() and returns the value if it's non-zero.
|
* otherwise just evaluates the conditional and returns the value.
|
||||||
*
|
|
||||||
* When CONFIG_SND_DEBUG is not set, this just returns zero, and the given
|
|
||||||
* condition is ignored.
|
|
||||||
*
|
|
||||||
* NOTE: the argument won't be evaluated at all when CONFIG_SND_DEBUG=n.
|
|
||||||
* Thus, don't put any statement that influences on the code behavior,
|
|
||||||
* such as pre/post increment, to the argument of this macro.
|
|
||||||
* If you want to evaluate and give a warning, use standard WARN_ON().
|
|
||||||
*/
|
*/
|
||||||
#define snd_BUG_ON(cond) WARN((cond), "BUG? (%s)\n", __stringify(cond))
|
#define snd_BUG_ON(cond) WARN_ON((cond))
|
||||||
|
|
||||||
#else /* !CONFIG_SND_DEBUG */
|
#else /* !CONFIG_SND_DEBUG */
|
||||||
|
|
||||||
|
@ -400,11 +392,11 @@ __printf(2, 3)
|
||||||
static inline void _snd_printd(int level, const char *format, ...) {}
|
static inline void _snd_printd(int level, const char *format, ...) {}
|
||||||
|
|
||||||
#define snd_BUG() do { } while (0)
|
#define snd_BUG() do { } while (0)
|
||||||
static inline int __snd_bug_on(int cond)
|
|
||||||
{
|
#define snd_BUG_ON(condition) ({ \
|
||||||
return 0;
|
int __ret_warn_on = !!(condition); \
|
||||||
}
|
unlikely(__ret_warn_on); \
|
||||||
#define snd_BUG_ON(cond) __snd_bug_on(0 && (cond)) /* always false */
|
})
|
||||||
|
|
||||||
#endif /* CONFIG_SND_DEBUG */
|
#endif /* CONFIG_SND_DEBUG */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue