ASoC: Intel: bdw_rt286: add checks to avoid static analysis warnings
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Mon, 31 Jul 2023 21:37:46 +0000 (16:37 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 31 Jul 2023 22:22:17 +0000 (23:22 +0100)
commit64778b022e629b8ffa97d23a9adbf670aa3bb1d8
treeab34e0b921bc2d7699c81b334a6f126c6c887df5
parent8cf5286216dcfb942f0e4d7c23ebe06c2ebc1bed
ASoC: Intel: bdw_rt286: add checks to avoid static analysis warnings

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@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Yaochun Hung <yc.hung@mediatek.com>
Link: https://lore.kernel.org/r/20230731213748.440285-7-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/bdw_rt286.c