Commit d1eb913c authored by Ivan Orlov's avatar Ivan Orlov Committed by Takashi Iwai

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.
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20240125223522.1122765-2-ivan.orlov0322@gmail.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent f7c4cb4a
...@@ -225,9 +225,11 @@ static const char * const snd_pcm_format_names[] = { ...@@ -225,9 +225,11 @@ static const char * const snd_pcm_format_names[] = {
*/ */
const char *snd_pcm_format_name(snd_pcm_format_t format) 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 "Unknown";
return snd_pcm_format_names[(__force unsigned int)format]; return snd_pcm_format_names[format_num];
} }
EXPORT_SYMBOL_GPL(snd_pcm_format_name); EXPORT_SYMBOL_GPL(snd_pcm_format_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment