Re: [ammarfaizi2-block:broonie/sound/for-5.18 33/171] sound/soc/sof/compress.c:54 snd_sof_compr_fragment_elapsed() warn: variable dereferenced before check 'cstream' (see line 48)

From: Ammar Faizi
Date: Fri Mar 11 2022 - 17:54:30 EST


On 3/12/22 1:59 AM, Dan Carpenter wrote:
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
sound/soc/sof/compress.c:54 snd_sof_compr_fragment_elapsed() warn: variable dereferenced before check 'cstream' (see line 48)

vim +/cstream +54 sound/soc/sof/compress.c

858f7a5c45cacb Daniel Baluta 2021-10-04 46 void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream)
858f7a5c45cacb Daniel Baluta 2021-10-04 47 {
6324cf901e14c6 Daniel Baluta 2022-01-20 @48 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
^^^^^^^^^^^^^^^^^^^^^^
6324cf901e14c6 Daniel Baluta 2022-01-20 49 struct snd_compr_runtime *crtd = cstream->runtime;
^^^^^^^^^^^^^^^^^
Dereference

858f7a5c45cacb Daniel Baluta 2021-10-04 50 struct snd_soc_component *component;
6324cf901e14c6 Daniel Baluta 2022-01-20 51 struct snd_compr_tstamp *tstamp;
858f7a5c45cacb Daniel Baluta 2021-10-04 52 struct snd_sof_pcm *spcm;
858f7a5c45cacb Daniel Baluta 2021-10-04 53
858f7a5c45cacb Daniel Baluta 2021-10-04 @54 if (!cstream)
^^^^^^^^
Checked too late

Hi Dan,

Thanks for reporting, it has already been fixed in commit
7e4bfcf10a03981 ("ASoC: SOF: compress: fix null check after dereference")

Link: https://git.kernel.org/broonie/sound/c/7e4bfcf10a03981

Regards,
--
Ammar Faizi