[PATCH 6/8] ASoC: Intel: bdw_rt286: add checks to avoid static analysis warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



snd_soc_card_get_codec_dai() can return NULL, but that value is not
checked for, leading to false-positive static analysis warnings

sound/soc/intel/boards/bdw_rt286.c:190:16: error: dereference of NULL
‘codec_dai’ [CWE-476] [-Werror=analyzer-null-dereference]

  190 |         return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘card_suspend_pre’: event 1
    |
    |  190 |         return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
    |      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                |
    |      |                (1) dereference of NULL ‘codec_dai’

This NULL dereference cannot happen, the codec-dai "rt286-aif1" must exists
otherwise the card would not be created. Static analysis cannot know
that however so we might as well squelch this report.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx>
Reviewed-by: Rander Wang <rander.wang@xxxxxxxxx>
Reviewed-by: Daniel Baluta <daniel.baluta@xxxxxxx>
Reviewed-by: Yaochun Hung <yc.hung@xxxxxxxxxxxx>
---
 sound/soc/intel/boards/bdw_rt286.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/soc/intel/boards/bdw_rt286.c b/sound/soc/intel/boards/bdw_rt286.c
index b7687a93a923..036579331d8f 100644
--- a/sound/soc/intel/boards/bdw_rt286.c
+++ b/sound/soc/intel/boards/bdw_rt286.c
@@ -187,6 +187,9 @@ static int card_suspend_pre(struct snd_soc_card *card)
 {
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, "rt286-aif1");
 
+	if (!codec_dai)
+		return 0;
+
 	return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
 }
 
@@ -194,6 +197,9 @@ static int card_resume_post(struct snd_soc_card *card)
 {
 	struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, "rt286-aif1");
 
+	if (!codec_dai)
+		return 0;
+
 	return snd_soc_component_set_jack(codec_dai->component, &card_headset, NULL);
 }
 
-- 
2.39.2




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux