]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
ALSA: Introduce snd_BUG_ON() macro
authorTakashi Iwai <tiwai@suse.de>
Fri, 8 Aug 2008 15:06:01 +0000 (17:06 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 13 Aug 2008 09:46:32 +0000 (11:46 +0200)
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>
Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
include/sound/core.h

index e13c4e67029f497899d4cbc545f67fd073d36e1f..df699e4323ef62a3cfe3afce586d5e4d8b225eae 100644 (file)
@@ -6173,6 +6173,47 @@ struct _snd_pcm_runtime {
         When no debug flag is set, this macro is ignored. 
       </para>
     </section>
+
+    <section id="useful-functions-snd-bug-on">
+      <title><function>snd_BUG_ON()</function></title>
+      <para>
+        <function>snd_BUG_ON()</function> macro is similar with
+       <function>WARN_ON()</function> macro. For example,  
+
+        <informalexample>
+          <programlisting>
+<![CDATA[
+  snd_BUG_ON(!pointer);
+]]>
+          </programlisting>
+        </informalexample>
+
+       or it can be used as the condition,
+        <informalexample>
+          <programlisting>
+<![CDATA[
+  if (snd_BUG_ON(non_zero_is_bug))
+          return -EINVAL;
+]]>
+          </programlisting>
+        </informalexample>
+
+      </para>
+
+      <para>
+        The macro takes an conditional expression to evaluate.
+       When <constant>CONFIG_SND_DEBUG</constant>, is set, the
+       expression is actually evaluated. If it's non-zero, it shows
+       the warning message such as
+       <computeroutput>BUG? (xxx)</computeroutput>
+       normally followed by stack trace.  It returns the evaluated
+       value.
+       When no <constant>CONFIG_SND_DEBUG</constant> is set, this
+       macro always returns zero.
+      </para>
+
+    </section>
+
   </chapter>
 
 
index 1a4ff0bdcf6ab45fa8dc0e50c80daa9c742b40d7..938c36a0e874f5514ad1fdbedc753a68de2b6603 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/rwsem.h>               /* struct rw_semaphore */
 #include <linux/pm.h>                  /* pm_message_t */
 #include <linux/device.h>
+#include <linux/stringify.h>
 
 /* number of supported soundcards */
 #ifdef CONFIG_SND_DYNAMIC_MINORS
@@ -405,11 +406,14 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
        dump_stack();                           \
 } while (0)
 
+#define snd_BUG_ON(cond)       WARN((cond), "BUG? (%s)\n", __stringify(cond))
+
 #else /* !CONFIG_SND_DEBUG */
 
 #define snd_printd(fmt, args...)       /* nothing */
 #define snd_assert(expr, args...)      (void)(expr)
 #define snd_BUG()                      /* nothing */
+#define snd_BUG_ON(cond)       ({/*(void)(cond);*/ 0;})  /* always false */
 
 #endif /* CONFIG_SND_DEBUG */