[alsa-devel] [PATCH 1/2] ALSA: core: add snd_pcm_format_by_name()

Takashi Iwai tiwai at suse.de
Thu Dec 5 09:25:32 CET 2019


On Thu, 05 Dec 2019 09:14:27 +0100,
Daniel Mack wrote:
> 
> Add a new function to look up PCM format codes by name. This can be used
> by ASoC drivers to look up formats through device-tree properties, for
> instance.
> 
> Signed-off-by: Daniel Mack <daniel at zonque.org>
> ---
>  include/sound/pcm.h |  1 +
>  sound/core/pcm.c    | 12 ++++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index bbe6eb1ff5d2..ce398caf12ba 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -1339,6 +1339,7 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
>  #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
>  
>  const char *snd_pcm_format_name(snd_pcm_format_t format);
> +snd_pcm_format_t snd_pcm_format_by_name(const char *name);
>  
>  /**
>   * snd_pcm_stream_str - Get a string naming the direction of a stream
> diff --git a/sound/core/pcm.c b/sound/core/pcm.c
> index 9a72d641743d..248f2dca7a12 100644
> --- a/sound/core/pcm.c
> +++ b/sound/core/pcm.c
> @@ -225,6 +225,18 @@ const char *snd_pcm_format_name(snd_pcm_format_t format)
>  }
>  EXPORT_SYMBOL_GPL(snd_pcm_format_name);
>  
> +snd_pcm_format_t snd_pcm_format_by_name(const char *name)
> +{

Could you give the proper document in kernel-doc style?
We try to provide some documentation at least for public API
functions.

> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(snd_pcm_format_names); i++)
> +		if (strcasecmp(name, snd_pcm_format_names[i]) == 0)
> +			return i;
> +
> +	return -ENOENT;

snd_pcm_format_t is with __bitwise, hence this would lead to some
warning for sparse, I guess.


thanks,

Takashi


More information about the Alsa-devel mailing list