[alsa-devel] export pcm_debug_name?

Takashi Iwai tiwai at suse.de
Fri Apr 1 15:07:04 CEST 2011


At Fri, 01 Apr 2011 12:41:15 +1300,
Eliot Blennerhassett wrote:
> 
> On 31/03/11 22:52, Takashi Iwai wrote:
> > At Thu, 31 Mar 2011 11:08:24 +1300,
> > Eliot Blennerhassett wrote:
> >>
> >> 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" ?

Yes, I suppose so.


> 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[]?

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


More information about the Alsa-devel mailing list