From: Takashi Iwai Subject: Re: export pcm_debug_name? Date: Fri, 01 Apr 2011 15:07:04 +0200 Message-ID: References: <4D93A9D8.2090104@audioscience.com> <4D95111B.2090209@audioscience.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id 05D8610381A for ; Fri, 1 Apr 2011 15:07:09 +0200 (CEST) In-Reply-To: <4D95111B.2090209@audioscience.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Eliot Blennerhassett Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org 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