Skip to contentSkip to conversation

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

PATCH In review [email protected] 2 participants 2 messages Oct 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

From: HariKrishna Sagala <[email protected]>

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.

---
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(-)
sound/soc/soc-dai.c +3 -2
index f231b4174b5f..a1e05307067d 100644
@@ -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

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · On Thu, 30 Oct 2025 16:23:14 +0530, [email protected] wrote:

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.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

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

      commit: e73b743bfe8a6ff4e05b5657d3f7586a17ac3ba0

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark