Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-core: check ops & auto_selectable_formats in snd_soc_dai_get_fmt() to prevent dereference error

Smatch reported an issue that "ops" could be null (see
line 174) where later "ops" is dereferenced to extract
the dai fmts, also auto_selectable_formats can also be
null.

Add a proper null check before accessing both the ptrs
to ensure a safe execution.

Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
Link: https://patch.msgid.link/20251030105313.32199-2-hariconscious@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

HariKrishna Sagala and committed by
Mark Brown
e73b743b 6ef8e042

+3 -2
+3 -2
sound/soc/soc-dai.c
··· 177 177 if (max < until) 178 178 until = max; 179 179 180 - for (i = 0; i < until; i++) 181 - fmt |= ops->auto_selectable_formats[i]; 180 + if (ops && ops->auto_selectable_formats) 181 + for (i = 0; i < until; i++) 182 + fmt |= ops->auto_selectable_formats[i]; 182 183 183 184 return fmt; 184 185 }