aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/misc.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-08-27 10:45:07 -0400
committerTakashi Iwai <tiwai@suse.de>2009-08-27 11:42:08 -0400
commit36ce99c1dcab2978fc1900f19b431adedd8f99f6 (patch)
tree5023629848d50243df8bbb780fde50468fd6acd3 /sound/core/misc.c
parent1b0053a0f0893e6bbaaee0d28f5f6269459d8d14 (diff)
ALSA: Add debug module option
Add debug module option to snd core. This controls the debug print level. When CONFIG_SND_DEBUG_VERBOSE is set, you can suppress the debug messages by giving or changing this parameter to a lower value. debug=0 means no debug messsages. As default, it's set to the verbose level 2. Since this option can be changed dynamically via sysfs file, you can suppress the verbose debug messages on the fly, which wasn't possible before. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/misc.c')
-rw-r--r--sound/core/misc.c67
1 files changed, 39 insertions, 28 deletions
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 1d29e678369e..23a032c6d487 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -24,6 +24,20 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <sound/core.h> 25#include <sound/core.h>
26 26
27#ifdef CONFIG_SND_DEBUG
28
29#ifdef CONFIG_SND_DEBUG_VERBOSE
30#define DEFAULT_DEBUG_LEVEL 2
31#else
32#define DEFAULT_DEBUG_LEVEL 1
33#endif
34
35static int debug = DEFAULT_DEBUG_LEVEL;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "Debug level (0 = disable)");
38
39#endif /* CONFIG_SND_DEBUG */
40
27void release_and_free_resource(struct resource *res) 41void release_and_free_resource(struct resource *res)
28{ 42{
29 if (res) { 43 if (res) {
@@ -35,6 +49,7 @@ void release_and_free_resource(struct resource *res)
35EXPORT_SYMBOL(release_and_free_resource); 49EXPORT_SYMBOL(release_and_free_resource);
36 50
37#ifdef CONFIG_SND_VERBOSE_PRINTK 51#ifdef CONFIG_SND_VERBOSE_PRINTK
52/* strip the leading path if the given path is absolute */
38static const char *sanity_file_name(const char *path) 53static const char *sanity_file_name(const char *path)
39{ 54{
40 if (*path == '/') 55 if (*path == '/')
@@ -43,48 +58,44 @@ static const char *sanity_file_name(const char *path)
43 return path; 58 return path;
44} 59}
45 60
46void snd_verbose_printk(const char *path, int line, const char *format, ...) 61/* print file and line with a certain printk prefix */
62static int print_snd_pfx(unsigned int level, const char *path, int line,
63 const char *format)
47{ 64{
48 const char *file = sanity_file_name(path); 65 const char *file = sanity_file_name(path);
49 va_list args; 66 char tmp[] = "<0>";
50 67 const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;
51 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') { 68 int ret = 0;
52 char tmp[] = "<0>"; 69
70 if (format[0] == '<' && format[2] == '>') {
53 tmp[1] = format[1]; 71 tmp[1] = format[1];
54 printk("%sALSA %s:%d: ", tmp, file, line); 72 pfx = tmp;
55 format += 3; 73 ret = 1;
56 } else {
57 printk("ALSA %s:%d: ", file, line);
58 } 74 }
59 va_start(args, format); 75 printk("%sALSA %s:%d: ", pfx, file, line);
60 vprintk(format, args); 76 return ret;
61 va_end(args);
62} 77}
63 78#else
64EXPORT_SYMBOL(snd_verbose_printk); 79#define print_snd_pfx(level, path, line, format) 0
65#endif 80#endif
66 81
67#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) 82#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
68void snd_verbose_printd(const char *path, int line, const char *format, ...) 83void __snd_printk(unsigned int level, const char *path, int line,
84 const char *format, ...)
69{ 85{
70 const char *file = sanity_file_name(path);
71 va_list args; 86 va_list args;
72 87
73 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') { 88#ifdef CONFIG_SND_DEBUG
74 char tmp[] = "<0>"; 89 if (debug < level)
75 tmp[1] = format[1]; 90 return;
76 printk("%sALSA %s:%d: ", tmp, file, line); 91#endif
77 format += 3;
78 } else {
79 printk(KERN_DEBUG "ALSA %s:%d: ", file, line);
80 }
81 va_start(args, format); 92 va_start(args, format);
93 if (print_snd_pfx(level, path, line, format))
94 format += 3; /* skip the printk level-prefix */
82 vprintk(format, args); 95 vprintk(format, args);
83 va_end(args); 96 va_end(args);
84
85} 97}
86 98EXPORT_SYMBOL_GPL(__snd_printk);
87EXPORT_SYMBOL(snd_verbose_printd);
88#endif 99#endif
89 100
90#ifdef CONFIG_PCI 101#ifdef CONFIG_PCI