From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
tiwai@suse.com, matthias.bgg@gmail.com
Cc: trevor.wu@mediatek.com, tzungbi@google.com,
dan.carpenter@oracle.com, jiaxin.yu@mediatek.com,
rikard.falkeborn@gmail.com, yc.hung@mediatek.com,
alsa-devel@alsa-project.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Xiaomeng Tong <xiam0nd.tong@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] mediatek: mt8195: fix a missing check on list iterator
Date: Sun, 27 Mar 2022 16:17:12 +0800 [thread overview]
Message-ID: <20220327081712.13341-1-xiam0nd.tong@gmail.com> (raw)
The bug is here:
mt8195_etdm_hw_params_fixup(runtime, params);
For the for_each_card_rtds(), just like list_for_each_entry(),
the list iterator 'runtime' will point to a bogus position
containing HEAD if the list is empty or no element is found.
This case must be checked before any use of the iterator,
otherwise it will lead to a invalid memory access.
To fix the bug, use a new variable 'iter' as the list iterator,
while use the original variable 'runtime' as a dedicated pointer
to point to the found element.
Cc: stable@vger.kernel.org
Fixes: 3d00d2c07f04f ("ASoC: mediatek: mt8195: add sof support on mt8195-mt6359-rt1019-rt5682")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
.../mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c b/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c
index 29c2d3407cc7..dc91877e4c3c 100644
--- a/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c
+++ b/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c
@@ -814,7 +814,7 @@ static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
{
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai_link *sof_dai_link = NULL;
- struct snd_soc_pcm_runtime *runtime;
+ struct snd_soc_pcm_runtime *runtime = NULL, *iter;
struct snd_soc_dai *cpu_dai;
int i, j, ret = 0;
@@ -824,16 +824,17 @@ static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
if (strcmp(rtd->dai_link->name, conn->normal_link))
continue;
- for_each_card_rtds(card, runtime) {
- if (strcmp(runtime->dai_link->name, conn->sof_link))
+ for_each_card_rtds(card, iter) {
+ if (strcmp(iter->dai_link->name, conn->sof_link))
continue;
- for_each_rtd_cpu_dais(runtime, j, cpu_dai) {
+ for_each_rtd_cpu_dais(iter, j, cpu_dai) {
if (cpu_dai->stream_active[conn->stream_dir] > 0) {
- sof_dai_link = runtime->dai_link;
+ sof_dai_link = iter->dai_link;
break;
}
}
+ runtime = iter;
break;
}
@@ -845,7 +846,8 @@ static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") ||
!strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) {
- mt8195_etdm_hw_params_fixup(runtime, params);
+ if (runtime)
+ mt8195_etdm_hw_params_fixup(runtime, params);
}
return ret;
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2022-03-27 8:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 8:17 Xiaomeng Tong [this message]
2022-03-29 2:33 ` [PATCH] mediatek: mt8195: fix a missing check on list iterator Trevor Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220327081712.13341-1-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=jiaxin.yu@mediatek.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=rikard.falkeborn@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
--cc=trevor.wu@mediatek.com \
--cc=tzungbi@google.com \
--cc=yc.hung@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).