[PATCH] ASoC: Intel: avs: Add null pointer check for es8366

Wentao Liang posted 1 patch 8 months, 4 weeks ago
sound/soc/intel/avs/boards/es8336.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] ASoC: Intel: avs: Add null pointer check for es8366
Posted by Wentao Liang 8 months, 4 weeks ago
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
Re: [PATCH] ASoC: Intel: avs: Add null pointer check for es8366
Posted by Cezary Rojewski 8 months, 4 weeks ago
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