diff mbox series

[v2,1/2] ALSA: core: add snd_pcm_format_by_name()

Message ID 20191205092129.692520-1-daniel@zonque.org (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] ALSA: core: add snd_pcm_format_by_name() | expand

Commit Message

Daniel Mack Dec. 5, 2019, 9:21 a.m. UTC
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@zonque.org>
---
 include/sound/pcm.h |  1 +
 sound/core/pcm.c    | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

kernel test robot Dec. 8, 2019, 6:39 a.m. UTC | #1
Hi Daniel,

I love your patch! Perhaps something to improve:

[auto build test WARNING on sound/for-next]
[also build test WARNING on asoc/for-next v5.4 next-20191207]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Daniel-Mack/ALSA-core-add-snd_pcm_format_by_name/20191207-084912
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-91-g817270f-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> sound/core/pcm.c:243:33: sparse: sparse: incorrect type in assignment (different base types) @@    expected restricted snd_pcm_format_t [usertype] @@    got t_t [usertype] @@
>> sound/core/pcm.c:243:33: sparse:    expected restricted snd_pcm_format_t [usertype]
>> sound/core/pcm.c:243:33: sparse:    got int [assigned] i
   sound/core/pcm.c:1022:9: sparse: sparse: context imbalance in 'snd_pcm_detach_substream' - different lock contexts for basic block

vim +243 sound/core/pcm.c

   227	
   228	/**
   229	 * snd_pcm_format_by_name - Return the PCM format code for the given name
   230	 * @name: PCM format name ('S16_LE', 'S24_3LE', ...)
   231	 * @format: Pointer to returned PCM format code
   232	 *
   233	 * The string comparison is done in a case-insensitive way.
   234	 *
   235	 * Return: 0 on success, or -ENOENT if the given format is not valid.
   236	 */
   237	int snd_pcm_format_by_name(const char *name, snd_pcm_format_t *format)
   238	{
   239		int i;
   240	
   241		for (i = 0; i < ARRAY_SIZE(snd_pcm_format_names); i++)
   242			if (strcasecmp(name, snd_pcm_format_names[i]) == 0) {
 > 243				*format = i;
   244				return 0;
   245			}
   246	
   247		return -ENOENT;
   248	}
   249	EXPORT_SYMBOL_GPL(snd_pcm_format_by_name);
   250	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
diff mbox series

Patch

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 8a89fa6fdd5e..1bfde6f2f180 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)
 					 (IEC958_AES3_CON_FS_48000<<24))
 
 const char *snd_pcm_format_name(snd_pcm_format_t format);
+int snd_pcm_format_by_name(const char *name, snd_pcm_format_t *format);
 
 /**
  * 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..c02d8df4f92b 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -225,6 +225,29 @@  const char *snd_pcm_format_name(snd_pcm_format_t format)
 }
 EXPORT_SYMBOL_GPL(snd_pcm_format_name);
 
+/**
+ * snd_pcm_format_by_name - Return the PCM format code for the given name
+ * @name: PCM format name ('S16_LE', 'S24_3LE', ...)
+ * @format: Pointer to returned PCM format code
+ *
+ * The string comparison is done in a case-insensitive way.
+ *
+ * Return: 0 on success, or -ENOENT if the given format is not valid.
+ */
+int snd_pcm_format_by_name(const char *name, snd_pcm_format_t *format)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(snd_pcm_format_names); i++)
+		if (strcasecmp(name, snd_pcm_format_names[i]) == 0) {
+			*format = i;
+			return 0;
+		}
+
+	return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(snd_pcm_format_by_name);
+
 #ifdef CONFIG_SND_VERBOSE_PROCFS
 
 #define STATE(v) [SNDRV_PCM_STATE_##v] = #v