Skip to content

Commit 36ce99c

Browse files
committed
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>
1 parent 1b0053a commit 36ce99c

3 files changed

Lines changed: 59 additions & 52 deletions

File tree

‎Documentation/sound/alsa/ALSA-Configuration.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
6060
slots - Reserve the slot index for the given driver.
6161
This option takes multiple strings.
6262
See "Module Autoloading Support" section for details.
63+
debug - Specifies the debug message level
64+
(0 = disable debug prints, 1 = normal debug messages,
65+
2 = verbose debug messages)
66+
This option appears only when CONFIG_SND_DEBUG=y.
67+
This option can be dynamically changed via sysfs
68+
/sys/modules/snd/parameters/debug file.
6369

6470
Module snd-pcm-oss
6571
------------------

‎include/sound/core.h‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,17 @@ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
340340
struct resource;
341341
void release_and_free_resource(struct resource *res);
342342

343-
#ifdef CONFIG_SND_VERBOSE_PRINTK
344-
void snd_verbose_printk(const char *file, int line, const char *format, ...)
345-
__attribute__ ((format (printf, 3, 4)));
346-
#endif
347-
#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
348-
void snd_verbose_printd(const char *file, int line, const char *format, ...)
349-
__attribute__ ((format (printf, 3, 4)));
350-
#endif
351-
352343
/* --- */
353344

354-
#ifdef CONFIG_SND_VERBOSE_PRINTK
345+
#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
346+
void __snd_printk(unsigned int level, const char *file, int line,
347+
const char *format, ...)
348+
__attribute__ ((format (printf, 4, 5)));
349+
#else
350+
#define __snd_printk(level, file, line, format, args...) \
351+
prinkt(format, ##args)
352+
#endif
353+
355354
/**
356355
* snd_printk - printk wrapper
357356
* @fmt: format string
@@ -360,15 +359,9 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
360359
* when configured with CONFIG_SND_VERBOSE_PRINTK.
361360
*/
362361
#define snd_printk(fmt, args...) \
363-
snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
364-
#else
365-
#define snd_printk(fmt, args...) \
366-
printk(fmt ,##args)
367-
#endif
362+
__snd_printk(0, __FILE__, __LINE__, fmt, ##args)
368363

369364
#ifdef CONFIG_SND_DEBUG
370-
371-
#ifdef CONFIG_SND_VERBOSE_PRINTK
372365
/**
373366
* snd_printd - debug printk
374367
* @fmt: format string
@@ -377,11 +370,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
377370
* Ignored when CONFIG_SND_DEBUG is not set.
378371
*/
379372
#define snd_printd(fmt, args...) \
380-
snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
381-
#else
382-
#define snd_printd(fmt, args...) \
383-
printk(fmt ,##args)
384-
#endif
373+
__snd_printk(1, __FILE__, __LINE__, fmt, ##args)
385374

386375
/**
387376
* snd_BUG - give a BUG warning message and stack trace
@@ -428,9 +417,10 @@ static inline int __snd_bug_on(int cond)
428417
* Works like snd_printk() for debugging purposes.
429418
* Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
430419
*/
431-
#define snd_printdd(format, args...) snd_printk(format, ##args)
420+
#define snd_printdd(format, args...) \
421+
__snd_printk(2, __FILE__, __LINE__, format, ##args)
432422
#else
433-
#define snd_printdd(format, args...) /* nothing */
423+
#define snd_printdd(format, args...) do { } while (0)
434424
#endif
435425

436426

‎sound/core/misc.c‎

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
#include <linux/ioport.h>
2525
#include <sound/core.h>
2626

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+
35+
static int debug = DEFAULT_DEBUG_LEVEL;
36+
module_param(debug, int, 0644);
37+
MODULE_PARM_DESC(debug, "Debug level (0 = disable)");
38+
39+
#endif /* CONFIG_SND_DEBUG */
40+
2741
void release_and_free_resource(struct resource *res)
2842
{
2943
if (res) {
@@ -35,6 +49,7 @@ void release_and_free_resource(struct resource *res)
3549
EXPORT_SYMBOL(release_and_free_resource);
3650

3751
#ifdef CONFIG_SND_VERBOSE_PRINTK
52+
/* strip the leading path if the given path is absolute */
3853
static const char *sanity_file_name(const char *path)
3954
{
4055
if (*path == '/')
@@ -43,48 +58,44 @@ static const char *sanity_file_name(const char *path)
4358
return path;
4459
}
4560

46-
void snd_verbose_printk(const char *path, int line, const char *format, ...)
61+
/* print file and line with a certain printk prefix */
62+
static int print_snd_pfx(unsigned int level, const char *path, int line,
63+
const char *format)
4764
{
4865
const char *file = sanity_file_name(path);
49-
va_list args;
50-
51-
if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
52-
char tmp[] = "<0>";
66+
char tmp[] = "<0>";
67+
const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;
68+
int ret = 0;
69+
70+
if (format[0] == '<' && format[2] == '>') {
5371
tmp[1] = format[1];
54-
printk("%sALSA %s:%d: ", tmp, file, line);
55-
format += 3;
56-
} else {
57-
printk("ALSA %s:%d: ", file, line);
72+
pfx = tmp;
73+
ret = 1;
5874
}
59-
va_start(args, format);
60-
vprintk(format, args);
61-
va_end(args);
75+
printk("%sALSA %s:%d: ", pfx, file, line);
76+
return ret;
6277
}
63-
64-
EXPORT_SYMBOL(snd_verbose_printk);
78+
#else
79+
#define print_snd_pfx(level, path, line, format) 0
6580
#endif
6681

67-
#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
68-
void snd_verbose_printd(const char *path, int line, const char *format, ...)
82+
#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
83+
void __snd_printk(unsigned int level, const char *path, int line,
84+
const char *format, ...)
6985
{
70-
const char *file = sanity_file_name(path);
7186
va_list args;
7287

73-
if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
74-
char tmp[] = "<0>";
75-
tmp[1] = format[1];
76-
printk("%sALSA %s:%d: ", tmp, file, line);
77-
format += 3;
78-
} else {
79-
printk(KERN_DEBUG "ALSA %s:%d: ", file, line);
80-
}
88+
#ifdef CONFIG_SND_DEBUG
89+
if (debug < level)
90+
return;
91+
#endif
8192
va_start(args, format);
93+
if (print_snd_pfx(level, path, line, format))
94+
format += 3; /* skip the printk level-prefix */
8295
vprintk(format, args);
8396
va_end(args);
84-
8597
}
86-
87-
EXPORT_SYMBOL(snd_verbose_printd);
98+
EXPORT_SYMBOL_GPL(__snd_printk);
8899
#endif
89100

90101
#ifdef CONFIG_PCI

0 commit comments

Comments
 (0)