summaryrefslogtreecommitdiff
path: root/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c
diff options
context:
space:
mode:
authorTrevor Wu <trevor.wu@mediatek.com>2023-03-07 07:09:35 +0300
committerMark Brown <broonie@kernel.org>2023-03-13 17:08:37 +0300
commitff728899065922534d80170685fb807194d6487b (patch)
tree6c92f85855c4ea6d254cbb2535c15ebe68e5beda /sound/soc/mediatek/mt8195/mt8195-dai-pcm.c
parent4727d4d775654986913a21c35c7cfaf1ecdafd62 (diff)
downloadlinux-ff728899065922534d80170685fb807194d6487b.tar.xz
ASoC: mediatek: mt8195: add dai id check before accessing array
Coverity shows "afe_priv->dai_priv[dai_id] evaluates to an address that could be at negative offset of an array.". Add dai id check before accessing the array element. This ensures that the offset of an array must be a valid index. Signed-off-by: Trevor Wu <trevor.wu@mediatek.com> Link: https://lore.kernel.org/r/20230307040938.7484-2-trevor.wu@mediatek.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/mediatek/mt8195/mt8195-dai-pcm.c')
-rw-r--r--sound/soc/mediatek/mt8195/mt8195-dai-pcm.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c b/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c
index 051433689ff5..6d6d79300d51 100644
--- a/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c
+++ b/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c
@@ -122,17 +122,26 @@ static int mtk_dai_pcm_configure(struct snd_pcm_substream *substream,
struct snd_pcm_runtime * const runtime = substream->runtime;
struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
struct mt8195_afe_private *afe_priv = afe->platform_priv;
- struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id];
- unsigned int slave_mode = pcmif_priv->slave_mode;
- unsigned int lrck_inv = pcmif_priv->lrck_inv;
- unsigned int bck_inv = pcmif_priv->bck_inv;
- unsigned int fmt = pcmif_priv->format;
+ struct mtk_dai_pcmif_priv *pcmif_priv;
+ unsigned int slave_mode;
+ unsigned int lrck_inv;
+ unsigned int bck_inv;
+ unsigned int fmt;
unsigned int bit_width = dai->sample_bits;
unsigned int val = 0;
unsigned int mask = 0;
int fs = 0;
int mode = 0;
+ if (dai->id != MT8195_AFE_IO_PCM)
+ return -EINVAL;
+
+ pcmif_priv = afe_priv->dai_priv[dai->id];
+ slave_mode = pcmif_priv->slave_mode;
+ lrck_inv = pcmif_priv->lrck_inv;
+ bck_inv = pcmif_priv->bck_inv;
+ fmt = pcmif_priv->format;
+
/* sync freq mode */
fs = mt8195_afe_fs_timing(runtime->rate);
if (fs < 0)
@@ -230,10 +239,15 @@ static int mtk_dai_pcm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
{
struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
struct mt8195_afe_private *afe_priv = afe->platform_priv;
- struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id];
+ struct mtk_dai_pcmif_priv *pcmif_priv;
dev_dbg(dai->dev, "%s fmt 0x%x\n", __func__, fmt);
+ if (dai->id != MT8195_AFE_IO_PCM)
+ return -EINVAL;
+
+ pcmif_priv = afe_priv->dai_priv[dai->id];
+
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
pcmif_priv->format = MTK_DAI_PCM_FMT_I2S;