From: "Trevor Wu (吳文良)" <Trevor.Wu@mediatek.com>
To: "broonie@kernel.org" <broonie@kernel.org>,
"kuninori.morimoto.gx@renesas.com"
<kuninori.morimoto.gx@renesas.com>,
"tiwai@suse.com" <tiwai@suse.com>,
"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"perex@perex.cz" <perex@perex.cz>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Nicolas Prado <nfraprado@collabora.com>
Cc: "linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kernel@collabora.com" <kernel@collabora.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-sound@vger.kernel.org" <linux-sound@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH] ASoC: mediatek: Check num_codecs is not zero to avoid panic during probe
Date: Wed, 27 Nov 2024 05:28:58 +0000 [thread overview]
Message-ID: <ca99047569fe34f84cdf83cacb49cb047d5dc389.camel@mediatek.com> (raw)
In-Reply-To: <20241126-asoc-mtk-dummy-panic-v1-1-42d53e168d2e@collabora.com>
On Tue, 2024-11-26 at 15:09 -0500, Nícolas F. R. A. Prado wrote:
>
> Following commit 13f58267cda3 ("ASoC: soc.h: don't create dummy
> Component via COMP_DUMMY()"), COMP_DUMMY() became an array with zero
> length, and only gets populated with the dummy struct after the card
> is
> registered. Since the sound card driver's probe happens before the
> card
> registration, accessing any of the members of a dummy component
> during
> probe will result in undefined behavior.
>
> This can be observed in the mt8188 and mt8195 machine sound drivers.
> By
> omitting a dai link subnode in the sound card's node in the
> Devicetree,
> the default uninitialized dummy codec is used, and when its dai_name
> pointer gets passed to strcmp() it results in a null pointer
> dereference
> and a kernel panic.
>
> In addition to that, set_card_codec_info() in the generic helpers
> file,
> mtk-soundcard-driver.c, will populate a dai link with a dummy codec
> when
> a dai link node is present in DT but with no codec property.
>
> The result is that at probe time, a dummy codec can either be
> uninitialized with num_codecs = 0, or be an initialized dummy codec,
> with num_codecs = 1 and dai_name = "snd-soc-dummy-dai". In order to
> accommodate for both situations, check that num_codecs is not zero
> before accessing the codecs' fields but still check for the codec's
> dai
> name against "snd-soc-dummy-dai" as needed.
>
> While at it, also drop the check that dai_name is not null in the
> mt8192
> driver, introduced in commit 4d4e1b6319e5 ("ASoC: mediatek: mt8192:
> Check existence of dai_name before dereferencing"), as it is actually
> redundant given the preceding num_codecs != 0 check.
>
> Fixes: 13f58267cda3 ("ASoC: soc.h: don't create dummy Component via
> COMP_DUMMY()")
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---
>
Acked-by: Trevor Wu <trevor.wu@mediatek.com>
Thank you for the patch.
Thanks,
Trevor
next prev parent reply other threads:[~2024-11-27 5:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 20:09 Nícolas F. R. A. Prado
2024-11-27 0:15 ` Kuninori Morimoto
2024-11-27 2:59 ` Fei Shao
2024-11-27 5:28 ` Trevor Wu (吳文良) [this message]
2024-11-27 10:12 ` AngeloGioacchino Del Regno
2024-11-27 12:13 ` Mark Brown
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=ca99047569fe34f84cdf83cacb49cb047d5dc389.camel@mediatek.com \
--to=trevor.wu@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=kernel@collabora.com \
--cc=kuninori.morimoto.gx@renesas.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=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nfraprado@collabora.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.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
all inboxes | Powered by JetHome®