linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: avs: rt274: Add null pointer check for snd_soc_card_get_codec_dai()
@ 2025-05-14 14:19 Wentao Liang
  2025-05-15  9:23 ` Amadeusz Sławiński
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2025-05-14 14:19 UTC (permalink / raw)
  To: cezary.rojewski, liam.r.girdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, kai.vehmanen, pierre-louis.bossart, broonie,
	perex, tiwai
  Cc: kuninori.morimoto.gx, linux-sound, linux-kernel, Wentao Liang,
	stable

The avs_card_suspend_pre() and avs_card_resume_post() in rt274
calls the snd_soc_card_get_codec_dai(), but does not check its return
value which is a null pointer if the function fails. This can result
in a null pointer dereference. A proper implementation can be found
in acp5x_nau8821_hw_params() and card_suspend_pre().

Add a null pointer check for snd_soc_card_get_codec_dai() to avoid null
pointer dereference when the function fails.

Fixes: a08797afc1f9 ("ASoC: Intel: avs: rt274: Refactor jack handling")
Cc: stable@vger.kernel.org # v6.2
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 sound/soc/intel/avs/boards/rt274.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sound/soc/intel/avs/boards/rt274.c b/sound/soc/intel/avs/boards/rt274.c
index 4b6c02a40204..7a8b6ee79f4c 100644
--- a/sound/soc/intel/avs/boards/rt274.c
+++ b/sound/soc/intel/avs/boards/rt274.c
@@ -194,6 +194,11 @@ static int avs_card_suspend_pre(struct snd_soc_card *card)
 {
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, RT274_CODEC_DAI);
 
+	if (!codec_dai) {
+		dev_err(card->dev, "Codec dai not found\n");
+		return -EINVAL;
+	}
+
 	return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
 }
 
@@ -202,6 +207,11 @@ static int avs_card_resume_post(struct snd_soc_card *card)
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, RT274_CODEC_DAI);
 	struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
 
+	if (!codec_dai) {
+		dev_err(card->dev, "Codec dai not found\n");
+		return -EINVAL;
+	}
+
 	return snd_soc_component_set_jack(codec_dai->component, jack, NULL);
 }
 
-- 
2.42.0.windows.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: Intel: avs: rt274: Add null pointer check for snd_soc_card_get_codec_dai()
  2025-05-14 14:19 [PATCH] ASoC: Intel: avs: rt274: Add null pointer check for snd_soc_card_get_codec_dai() Wentao Liang
@ 2025-05-15  9:23 ` Amadeusz Sławiński
  0 siblings, 0 replies; 2+ messages in thread
From: Amadeusz Sławiński @ 2025-05-15  9:23 UTC (permalink / raw)
  To: Wentao Liang, cezary.rojewski, liam.r.girdwood, peter.ujfalusi,
	yung-chuan.liao, ranjani.sridharan, kai.vehmanen,
	pierre-louis.bossart, broonie, perex, tiwai
  Cc: kuninori.morimoto.gx, linux-sound, linux-kernel, stable



On 2025-05-14 16:19, Wentao Liang wrote:
> The avs_card_suspend_pre() and avs_card_resume_post() in rt274
> calls the snd_soc_card_get_codec_dai(), but does not check its return
> value which is a null pointer if the function fails. This can result
> in a null pointer dereference. A proper implementation can be found
> in acp5x_nau8821_hw_params() and card_suspend_pre().
> 
> Add a null pointer check for snd_soc_card_get_codec_dai() to avoid null
> pointer dereference when the function fails.
> 
> Fixes: a08797afc1f9 ("ASoC: Intel: avs: rt274: Refactor jack handling")
> Cc: stable@vger.kernel.org # v6.2
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   sound/soc/intel/avs/boards/rt274.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/sound/soc/intel/avs/boards/rt274.c b/sound/soc/intel/avs/boards/rt274.c
> index 4b6c02a40204..7a8b6ee79f4c 100644
> --- a/sound/soc/intel/avs/boards/rt274.c
> +++ b/sound/soc/intel/avs/boards/rt274.c
> @@ -194,6 +194,11 @@ static int avs_card_suspend_pre(struct snd_soc_card *card)
>   {
>   	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, RT274_CODEC_DAI);
>   
> +	if (!codec_dai) {
> +		dev_err(card->dev, "Codec dai not found\n");
> +		return -EINVAL;
> +	}
> +
>   	return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
>   }
>   
> @@ -202,6 +207,11 @@ static int avs_card_resume_post(struct snd_soc_card *card)
>   	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, RT274_CODEC_DAI);
>   	struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
>   
> +	if (!codec_dai) {
> +		dev_err(card->dev, "Codec dai not found\n");
> +		return -EINVAL;
> +	}
> +
>   	return snd_soc_component_set_jack(codec_dai->component, jack, NULL);
>   }
>   

Same as in other case, where Cezary commented - this is not needed, once 
card is loaded codec should exist.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-15  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 14:19 [PATCH] ASoC: Intel: avs: rt274: Add null pointer check for snd_soc_card_get_codec_dai() Wentao Liang
2025-05-15  9:23 ` Amadeusz Sławiński

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).