[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251030105313.32199-2-hariconscious@gmail.com>
Date: Thu, 30 Oct 2025 16:23:14 +0530
From: hariconscious@...il.com
To: lgirdwood@...il.com,
broonie@...nel.org,
perex@...ex.cz,
tiwai@...e.com
Cc: khalid@...nel.org,
shuah@...nel.org,
david.hunter.linux@...il.com,
linux-sound@...r.kernel.org,
linux-kernel@...r.kernel.org,
HariKrishna Sagala <hariconscious@...il.com>
Subject: [PATCH] ASoC: soc-core: check ops & auto_selectable_formats in snd_soc_dai_get_fmt() to prevent dereference error
From: HariKrishna Sagala <hariconscious@...il.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@...il.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
Powered by blists - more mailing lists