diff options
author | Takashi Iwai <tiwai@suse.de> | 2008-08-08 11:06:01 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-08-13 05:46:32 -0400 |
commit | 5ef03460a6ffc1d3ee6b6f2abc6765d3e224cf89 (patch) | |
tree | 1947acad9b61fa80567fa1dd20c5b8c65ff8a46d | |
parent | 3caf8c080ef0bd0ccdc20bb57b150b6e40a86fd3 (diff) |
ALSA: Introduce snd_BUG_ON() macro
Introduced snd_BUG_ON() macro as a replacement of snd_assert() macro.
snd_assert() is pretty ugly as it has the control flow in its argument.
OTOH, snd_BUG_ON() behaves like a normal conditional, thus it's much
easier to read the flow.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl | 41 | ||||
-rw-r--r-- | include/sound/core.h | 4 |
2 files changed, 45 insertions, 0 deletions
diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl index e13c4e67029f..df699e4323ef 100644 --- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl +++ b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl | |||
@@ -6173,6 +6173,47 @@ struct _snd_pcm_runtime { | |||
6173 | When no debug flag is set, this macro is ignored. | 6173 | When no debug flag is set, this macro is ignored. |
6174 | </para> | 6174 | </para> |
6175 | </section> | 6175 | </section> |
6176 | |||
6177 | <section id="useful-functions-snd-bug-on"> | ||
6178 | <title><function>snd_BUG_ON()</function></title> | ||
6179 | <para> | ||
6180 | <function>snd_BUG_ON()</function> macro is similar with | ||
6181 | <function>WARN_ON()</function> macro. For example, | ||
6182 | |||
6183 | <informalexample> | ||
6184 | <programlisting> | ||
6185 | <![CDATA[ | ||
6186 | snd_BUG_ON(!pointer); | ||
6187 | ]]> | ||
6188 | </programlisting> | ||
6189 | </informalexample> | ||
6190 | |||
6191 | or it can be used as the condition, | ||
6192 | <informalexample> | ||
6193 | <programlisting> | ||
6194 | <![CDATA[ | ||
6195 | if (snd_BUG_ON(non_zero_is_bug)) | ||
6196 | return -EINVAL; | ||
6197 | ]]> | ||
6198 | </programlisting> | ||
6199 | </informalexample> | ||
6200 | |||
6201 | </para> | ||
6202 | |||
6203 | <para> | ||
6204 | The macro takes an conditional expression to evaluate. | ||
6205 | When <constant>CONFIG_SND_DEBUG</constant>, is set, the | ||
6206 | expression is actually evaluated. If it's non-zero, it shows | ||
6207 | the warning message such as | ||
6208 | <computeroutput>BUG? (xxx)</computeroutput> | ||
6209 | normally followed by stack trace. It returns the evaluated | ||
6210 | value. | ||
6211 | When no <constant>CONFIG_SND_DEBUG</constant> is set, this | ||
6212 | macro always returns zero. | ||
6213 | </para> | ||
6214 | |||
6215 | </section> | ||
6216 | |||
6176 | </chapter> | 6217 | </chapter> |
6177 | 6218 | ||
6178 | 6219 | ||
diff --git a/include/sound/core.h b/include/sound/core.h index 1a4ff0bdcf6a..938c36a0e874 100644 --- a/include/sound/core.h +++ b/include/sound/core.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/rwsem.h> /* struct rw_semaphore */ | 28 | #include <linux/rwsem.h> /* struct rw_semaphore */ |
29 | #include <linux/pm.h> /* pm_message_t */ | 29 | #include <linux/pm.h> /* pm_message_t */ |
30 | #include <linux/device.h> | 30 | #include <linux/device.h> |
31 | #include <linux/stringify.h> | ||
31 | 32 | ||
32 | /* number of supported soundcards */ | 33 | /* number of supported soundcards */ |
33 | #ifdef CONFIG_SND_DYNAMIC_MINORS | 34 | #ifdef CONFIG_SND_DYNAMIC_MINORS |
@@ -405,11 +406,14 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...) | |||
405 | dump_stack(); \ | 406 | dump_stack(); \ |
406 | } while (0) | 407 | } while (0) |
407 | 408 | ||
409 | #define snd_BUG_ON(cond) WARN((cond), "BUG? (%s)\n", __stringify(cond)) | ||
410 | |||
408 | #else /* !CONFIG_SND_DEBUG */ | 411 | #else /* !CONFIG_SND_DEBUG */ |
409 | 412 | ||
410 | #define snd_printd(fmt, args...) /* nothing */ | 413 | #define snd_printd(fmt, args...) /* nothing */ |
411 | #define snd_assert(expr, args...) (void)(expr) | 414 | #define snd_assert(expr, args...) (void)(expr) |
412 | #define snd_BUG() /* nothing */ | 415 | #define snd_BUG() /* nothing */ |
416 | #define snd_BUG_ON(cond) ({/*(void)(cond);*/ 0;}) /* always false */ | ||
413 | 417 | ||
414 | #endif /* CONFIG_SND_DEBUG */ | 418 | #endif /* CONFIG_SND_DEBUG */ |
415 | 419 | ||