Skip to contentSkip to conversation

export pcm_debug_name?

DISCUSSION Eliot Blennerhassett 2 participants 4 messages Mar 30, 2011 – Apr 1, 2011

lore
Share & tools
lore
#0 lore raw

Currently defined locally in pcm_lib.c, this function would be useful for debug output from drivers too?

Any objection to exporting this function?

Quoted 9 lines

static void pcm_debug_name(struct snd_pcm_substream *substream,
char *name, size_t len)

{
	snprintf(name, len, "pcmC%dD%d%c:%d",
		 substream->pcm->card->number,
		 substream->pcm->device,
		 substream->stream ? 'c' : 'p',
		 substream->number);
}
Signature · 2 lines
Eliot Blennerhassett
AudioScience Inc.
#1 lore raw

At Thu, 31 Mar 2011 11:08:24 +1300,

Quoted 5 lines · Eliot Blennerhassett

Currently defined locally in pcm_lib.c, this function would be useful for debug output from drivers too?

Any objection to exporting this function?

It's fine to me. Or, can this be a static inline function?

thanks,

Takashi

Quoted 16 lines
Quoted 11 lines

static void pcm_debug_name(struct snd_pcm_substream *substream,
char *name, size_t len)

{
	snprintf(name, len, "pcmC%dD%d%c:%d",
		 substream->pcm->card->number,
		 substream->pcm->device,
		 substream->stream ? 'c' : 'p',
		 substream->number);
}
Signature · 2 lines
Eliot Blennerhassett
AudioScience Inc.
#2 lore raw
Quoted 9 lines · Takashi Iwai

At Thu, 31 Mar 2011 11:08:24 +1300,

Quoted 5 lines · Eliot Blennerhassett

Currently pcm_debug_name is defined locally in pcm_lib.c, this function would be useful for debug output from drivers too?

Any objection to exporting this function?

It's fine to me. Or, can this be a static inline function?

Thanks Takashi

I'm happy either way. I'd leave it to you and Jaroslav to decide.

BTW Should it become "snd_pcm_debug_name" ?

One thing I'm not sure about is whether this is a debug_only function, and if so, what to do about the necessary variable required to hold the name for printing? I.e when debug is turned off, will get warnings about unused variable "name"

#ifdef CONFIG_SND_DEBUG
static inline pcm_debug_name etc.
#else
#define pcm_debug_name(s,n,l) while (0) do {}
#endif

Typical usage

static int somefunc(struct snd_pcm_substream * substream) {
#ifdef CONFIG_SND_DEBUG
char name[16];
#endif

pcm_debug_name(substream, name, sizeof(name))
snd_printd("%s foo %d\n", name, other);
...
}

Is there a nice way to avoid the #ifdef around name[]?

--
Eliot

#3 lore raw

At Fri, 01 Apr 2011 12:41:15 +1300,

Quoted 10 lines · Eliot Blennerhassett
Quoted 8 lines · Takashi Iwai

At Thu, 31 Mar 2011 11:08:24 +1300,

Quoted 5 lines · Eliot Blennerhassett

Currently pcm_debug_name is defined locally in pcm_lib.c, this function would be useful for debug output from drivers too?

Any objection to exporting this function?

Quoted 7 lines
Quoted 1 line

It's fine to me. Or, can this be a static inline function?

Thanks Takashi

I'm happy either way. I'd leave it to you and Jaroslav to decide.

BTW Should it become "snd_pcm_debug_name" ?

Yes, I suppose so.

Quoted 19 lines

One thing I'm not sure about is whether this is a debug_only function, and if so, what to do about the necessary variable required to hold the name for printing? I.e when debug is turned off, will get warnings about unused variable "name"

#ifdef CONFIG_SND_DEBUG
static inline pcm_debug_name etc.
#else
#define pcm_debug_name(s,n,l) while (0) do {}
#endif

Typical usage

static int somefunc(struct snd_pcm_substream * substream) {
#ifdef CONFIG_SND_DEBUG
char name[16];
#endif

Quoted 6 lines

pcm_debug_name(substream, name, sizeof(name))
snd_printd("%s foo %d\n", name, other);
...
}

Is there a nice way to avoid the #ifdef around name[]?

I guess it can be avoided by defining a dummy function as static inline,

static inline void
snd_pcm_debug_name(struct snd_pcm_substream *stream, char *buf, size_t size) {
}

But, I'm not sure whether it's good. For example, in your case above, one might think to change from snd_printd() to printk(). Now you'll get garbages in the name field, and it might give Oops.
So, I guess at least it should initialize the string,

static inline void
snd_pcm_debug_name(struct snd_pcm_substream *stream, char *buf, size_t size)

{
	*buf = 0;
}

The compiler would optimize out such ops, anyway.

thanks,

Takashi