Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: avs: Add null pointer check for es8366
@ 2025-05-14 13:34 Wentao Liang
  2025-05-14 13:48 ` Cezary Rojewski
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2025-05-14 13:34 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, tony.luck, amadeuszx.slawinski, linux-sound,
	linux-kernel, Wentao Liang, stable

The avs_card_suspend_pre() and avs_card_resume_post() in es8336
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: 32e40c8d6ff9 ("ASoC: Intel: avs: Add es8336 machine board")
Cc: stable@vger.kernel.org # v6.6
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 sound/soc/intel/avs/boards/es8336.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/soc/intel/avs/boards/es8336.c b/sound/soc/intel/avs/boards/es8336.c
index 426ce37105ae..e31cc656f076 100644
--- a/sound/soc/intel/avs/boards/es8336.c
+++ b/sound/soc/intel/avs/boards/es8336.c
@@ -243,6 +243,9 @@ static int avs_card_suspend_pre(struct snd_soc_card *card)
 {
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, ES8336_CODEC_DAI);
 
+	if (!codec_dai)
+		return -EINVAL;
+
 	return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
 }
 
@@ -251,6 +254,9 @@ static int avs_card_resume_post(struct snd_soc_card *card)
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, ES8336_CODEC_DAI);
 	struct avs_card_drvdata *data = snd_soc_card_get_drvdata(card);
 
+	if (!codec_dai)
+		return -EINVAL;
+
 	return snd_soc_component_set_jack(codec_dai->component, &data->jack, NULL);
 }
 
-- 
2.42.0.windows.2


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

* Re: [PATCH] ASoC: Intel: avs: Add null pointer check for es8366
  2025-05-14 13:34 [PATCH] ASoC: Intel: avs: Add null pointer check for es8366 Wentao Liang
@ 2025-05-14 13:48 ` Cezary Rojewski
  0 siblings, 0 replies; 2+ messages in thread
From: Cezary Rojewski @ 2025-05-14 13:48 UTC (permalink / raw)
  To: Wentao Liang
  Cc: kuninori.morimoto.gx, tony.luck, amadeuszx.slawinski, linux-sound,
	linux-kernel, stable, liam.r.girdwood, peter.ujfalusi,
	yung-chuan.liao, ranjani.sridharan, kai.vehmanen,
	pierre-louis.bossart, broonie, perex, tiwai

On 2025-05-14 3:34 PM, Wentao Liang wrote:
> The avs_card_suspend_pre() and avs_card_resume_post() in es8336
> 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: 32e40c8d6ff9 ("ASoC: Intel: avs: Add es8336 machine board")
> Cc: stable@vger.kernel.org # v6.6
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   sound/soc/intel/avs/boards/es8336.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/sound/soc/intel/avs/boards/es8336.c b/sound/soc/intel/avs/boards/es8336.c
> index 426ce37105ae..e31cc656f076 100644
> --- a/sound/soc/intel/avs/boards/es8336.c
> +++ b/sound/soc/intel/avs/boards/es8336.c
> @@ -243,6 +243,9 @@ static int avs_card_suspend_pre(struct snd_soc_card *card)
>   {
>   	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, ES8336_CODEC_DAI);
>   
> +	if (!codec_dai)
> +		return -EINVAL;
> +
>   	return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
>   }
>   
> @@ -251,6 +254,9 @@ static int avs_card_resume_post(struct snd_soc_card *card)
>   	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, ES8336_CODEC_DAI);
>   	struct avs_card_drvdata *data = snd_soc_card_get_drvdata(card);
>   
> +	if (!codec_dai)
> +		return -EINVAL;
> +
>   	return snd_soc_component_set_jack(codec_dai->component, &data->jack, NULL);
>   }

Hi Wentao,

Thank you for the contribution but we do not NULL-check the result of 
snd_soc_card_get_codec_dai() wrapper. The machine board driver (also 
called sound card driver) never reaches this area if all the CPU and 
CODEC DAIs haven't been previously accounted for and verified. Flooding 
sound/soc/ with such checks is a waste of LOCs.

NACK

Kind regards,
Czarek

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

end of thread, other threads:[~2025-05-14 13:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 13:34 [PATCH] ASoC: Intel: avs: Add null pointer check for es8366 Wentao Liang
2025-05-14 13:48 ` Cezary Rojewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox