Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: soc-core: check ops & auto_selectable_formats in snd_soc_dai_get_fmt() to prevent dereference error
@ 2025-10-30 10:53 hariconscious
  2025-10-30 16:06 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: hariconscious @ 2025-10-30 10:53 UTC (permalink / raw)
  To: lgirdwood, broonie, perex, tiwai
  Cc: khalid, shuah, david.hunter.linux, linux-sound, linux-kernel,
	HariKrishna Sagala

From: HariKrishna Sagala <hariconscious@gmail.com>

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>
---
Hi,

Smatch flagged a null-pointer check in the function "snd_soc_dai_get_fmt". 
But the same validation is already performed in the earlier function call
"snd_soc_dai_get_fmt_max_priority" before calling into "snd_soc_dai_get_fmt".
While Smatch flags this, seeing it as a false positive, redundant null check 
added to make "snd_soc_dai_get_fmt" safe for independent reuse (if).

one way:
redundancy can also be removed in the line no.174

another way:
to have a null check considering independent functions

Please let me know.

Thanks.

 sound/soc/soc-dai.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c
index f231b4174b5f..a1e05307067d 100644
--- a/sound/soc/soc-dai.c
+++ b/sound/soc/soc-dai.c
@@ -177,8 +177,9 @@ u64 snd_soc_dai_get_fmt(const struct snd_soc_dai *dai, int priority)
 	if (max < until)
 		until = max;
 
-	for (i = 0; i < until; i++)
-		fmt |= ops->auto_selectable_formats[i];
+	if (ops && ops->auto_selectable_formats)
+		for (i = 0; i < until; i++)
+			fmt |= ops->auto_selectable_formats[i];
 
 	return fmt;
 }

base-commit: 6548d364a3e850326831799d7e3ea2d7bb97ba08
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-30 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 10:53 [PATCH] ASoC: soc-core: check ops & auto_selectable_formats in snd_soc_dai_get_fmt() to prevent dereference error hariconscious
2025-10-30 16:06 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox