ALSA: pcm: Add missing formats to formats list
Subsystems (2)
Ivan Orlov
maintainerPATCH 1/3 ALSA: pcm: Add missing formats to formats list
Add 4 missing formats to 'snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.
--- sound/core/pcm.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/core/pcm.c +4 -0
@@ -211,6 +211,10 @@ static const char * const snd_pcm_format_names[] = {FORMAT (DSD_U32_LE ),FORMAT (DSD_U16_BE ),FORMAT (DSD_U32_BE ), +FORMAT (S20_LE ), +FORMAT (S20_BE ), +FORMAT (U20_LE ), + FORMAT(U20_BE), };/**
Signature · 1 line
2.34.1
Ivan Orlov
maintainerPATCH 2/3 ALSA: pcm: Fix snd_pcm_format_name function
Fix snd_pcm_format_name so it won't return NULL-pointer in case if it can't find the format in the 'snd_pcm_format_names' list. Return "Unknown" instead, as it is done if the number passed to the function is larger than a list size.
--- sound/core/pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/core/pcm.c +4 -2
@@ -225,9 +225,11 @@ static const char * const snd_pcm_format_names[] = {*/ const char *snd_pcm_format_name (snd_pcm_format_t format) { -if ((__force unsigned int )format >=ARRAY_SIZE (snd_pcm_format_names)) +unsigned int format_num = (__force unsigned int )format; + +if (format_num >=ARRAY_SIZE (snd_pcm_format_names) || !snd_pcm_format_names[format_num])return "Unknown" ; -return snd_pcm_format_names[(__force unsigned int )format]; +return snd_pcm_format_names[format_num]; }EXPORT_SYMBOL_GPL (snd_pcm_format_name);
Signature · 1 line
2.34.1
Ivan Orlov
maintainerPATCH 3/3 ALSA: core: Add sound core KUnit test
In reply to Ivan OrlovAt the moment, we have a decent amount of integration tests (selftests) covering different aspects of the sound subsystem. However, a lot of of sound-related in-kernel functions remains uncovered. This patch introduces the KUnit test for the core part of the sound subsystem. It includes 10 test cases:
- Coverage of the format-related inline functions from 'pcm.h' header
file: snd_pcm_format_physical_width, snd_pcm_format_width, snd_pcm_format_signed, test_format_endianness
- Coverage of the available bytes counting functions from 'pcm.h'
header: snd_pcm_capture_avail, snd_pcm_playback_avail
- Coverage of functions from pcm_misc: snd_pcm_format_set_silence, snd_pcm_format_name
- Coverage of card-related functions from init.c: snd_card_set_id, snd_component_add
This patch depends on the previous patches in this patch series as they contain fix for the bug, which was found during the test development. Without them, the test doesn't pass.
--- MAINTAINERS | 6 + sound/core/Kconfig | 16 ++ sound/core/Makefile | 2 + sound/core/sound_kunit.c | 310 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 334 insertions(+) create mode 100644 sound/core/sound_kunit.c
MAINTAINERS +6 -0
@@ -20485,6 +20485,12 @@ F: include/uapi/sound/compress_* F: sound/core/compress_offload.c F: sound/soc/soc-compress.c +SOUND - CORE KUNIT TEST +M: Ivan Orlov <[email protected]> +L: [email protected] +S: Supported +F: sound/core/sound_kunit.c + SOUND - DMAENGINE HELPERS M: Lars-Peter Clausen <[email protected]> S: Supported
sound/core/Kconfig +16 -0
@@ -39,6 +39,22 @@ config SND_UMP_LEGACY_RAWMIDI legacy MIDI 1.0 byte streams is created for each UMP Endpoint. The device contains 16 substreams corresponding to UMP groups. +config SND_CORE_TEST + tristate "Sound core KUnit test" + depends on KUNIT + default KUNIT_ALL_TESTS + help + This options enables the sound core functions KUnit test. + + KUnit tests run during boot and output the results to the debug + log in TAP format (https://testanything.org/). Only useful for + kernel devs running KUnit test harness and are not for inclusion + into a production build. + + For more information on KUnit and unit tests in general, refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + config SND_COMPRESS_OFFLOAD tristate
sound/core/Makefile +2 -0
@@ -49,6 +49,8 @@ obj-$(CONFIG_SND_SEQ_DEVICE) += snd-seq-device.o obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o obj-$(CONFIG_SND_UMP) += snd-ump.o +obj-$(CONFIG_SND_CORE_TEST) += sound_kunit.o + obj-$(CONFIG_SND_OSSEMUL) += oss/ obj-$(CONFIG_SND_SEQUENCER) += seq/
sound/core/sound_kunit.c new file +310 -0
310 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 13 lines · Ivan Orlov
Add 4 missing formats to '
snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.Signed-off-by Ivan Orlov <[email protected]>--- sound/core/pcm.c | 4 ++++ 1 file changed, 4 insertions(+)sound/core/pcm.c +0
-0
sound/core/pcm.c static const char * const snd_pcm_format_names[] = { · line 220
Quoted 10 lines
sound/core/pcm.c +4
-0@@ -211,6 +211,10 @@ static const char * const snd_pcm_format_names[] = {FORMAT (DSD_U32_LE ),FORMAT (DSD_U16_BE ),FORMAT (DSD_U32_BE ), +FORMAT (S20_LE ), +FORMAT (S20_BE ), +FORMAT (U20_LE ), + FORMAT(U20_BE), };/**
Maybe we can also add some kind of static_assert to check at compile time that all formats are handled, something like:static_assert(ARRAY_SIZE(snd_pcm_format_names) == SNDRV_PCM_FORMAT_LAST + 1);
Although looking at definitions there is a hole between SNDRV_PCM_FORMAT_U20_BE & SNDRV_PCM_FORMAT_SPECIAL, which will cause this idea to fail.
Perhaps with comment:static_assert(ARRAY_SIZE(snd_pcm_format_names) == SNDRV_PCM_FORMAT_LAST + 1 - 2); /* -2 for formats reserved for future use */ ?
Ivan Orlov
maintainerQuoted 28 lines · Amadeusz Sławiński
Quoted 13 lines · Ivan Orlov
Add 4 missing formats to '
snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.Signed-off-by Ivan Orlov <[email protected]>---
sound/core/pcm.c| 4 ++++1 file changed, 4 insertions(+)sound/core/pcm.c +0
-0sound/core/pcm.c static const char * const snd_pcm_format_names[] = { · line 219
Quoted 9 lines
sound/core/pcm.c +4
-0@@ -211,6 +211,10 @@ static const char * const snd_pcm_format_names[] = { FORMAT(DSD_U32_LE), FORMAT(DSD_U16_BE), FORMAT(DSD_U32_BE), + FORMAT(S20_LE), + FORMAT(S20_BE), + FORMAT(U20_LE), + FORMAT(U20_BE), }; /**Maybe we can also add some kind of
static_assertto check at compile time that all formats are handled, something like:
static_assert(ARRAY_SIZE(snd_pcm_format_names) ==SNDRV_PCM_FORMAT_LAST
+ 1);
Quoted 6 lines
Although looking at definitions there is a hole between
SNDRV_PCM_FORMAT_U20_BE&SNDRV_PCM_FORMAT_SPECIAL, which will cause this idea to fail.Perhaps with comment:
static_assert(ARRAY_SIZE(snd_pcm_format_names) ==SNDRV_PCM_FORMAT_LAST
+ 1 - 2); /* -2 for formats reserved for future use */
?
Hi Amadeusz,
Thank you for the review and sorry for the late answer. Yes, I believe it could be a nice improvement! Could I send a patch and specify you in Suggested-by tag?
Signature · 2 lines
Kind regards, Ivan Orlov
Quoted 31 lines · Ivan Orlov
Quoted 30 lines · Amadeusz Sławiński
Quoted 13 lines · Ivan Orlov
Add 4 missing formats to '
snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.Signed-off-by Ivan Orlov <[email protected]>---
sound/core/pcm.c| 4 ++++1 file changed, 4 insertions(+)sound/core/pcm.c +0
-0sound/core/pcm.c static const char * const snd_pcm_format_names[] · line 220
Quoted 10 lines
sound/core/pcm.c +4
-0@@ -211,6 +211,10 @@ static const char * const snd_pcm_format_names[] = { FORMAT(DSD_U32_LE), FORMAT(DSD_U16_BE), FORMAT(DSD_U32_BE), + FORMAT(S20_LE), + FORMAT(S20_BE), + FORMAT(U20_LE), + FORMAT(U20_BE), }; /**Maybe we can also add some kind of
static_assertto check at compile time that all formats are handled, something like:static_assert(ARRAY_SIZE(snd_pcm_format_names) == SNDRV_PCM_FORMAT_LAST + 1);Although looking at definitions there is a hole between
SNDRV_PCM_FORMAT_U20_BE&SNDRV_PCM_FORMAT_SPECIAL, which will cause this idea to fail.
Quoted 8 lines
Quoted 3 lines
Perhaps with comment:
static_assert(ARRAY_SIZE(snd_pcm_format_names) == SNDRV_PCM_FORMAT_LAST + 1 - 2); /* -2 for formats reserved for future use */ ?Hi Amadeusz,
Thank you for the review and sorry for the late answer. Yes, I believe it could be a nice improvement! Could I send a patch and specify you in Suggested-by tag?
Hi,
yes, go for it!
Amadeusz
Quoted 5 lines · Ivan Orlov
Add 4 missing formats to '
snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.Signed-off-by Ivan Orlov <[email protected]>
Now applied all three patches. This first one is to for-linus, while the rest two are to for-next for 6.9 kernel.
For further improvements (e.g. Amadeusz suggested), let's apply on top of that.
thanks,
Takashi
Ivan Orlov
maintainerQuoted 11 lines · Takashi Iwai
Quoted 5 lines · Ivan Orlov
Add 4 missing formats to '
snd_pcm_format_names' array in order to be able to get their names with 'snd_pcm_format_name' function.Signed-off-by Ivan Orlov <[email protected]>Now applied all three patches. This first one is to for-linus, while the rest two are to for-next for 6.9 kernel.
Quoted 7 lines
For further improvements (e.g. Amadeusz suggested), let's apply on top of that.
thanks,
Takashi
Hi Takashi,
Thank you for applying this changes! I'll send the patch with the improvements suggested by Amadeusz as soon as possible.
Signature · 2 lines
Kind regards, Ivan Orlov