Skip to content

Commit

Permalink
ASoC: soc-compress: Change the check for codec_dai
Browse files Browse the repository at this point in the history
It should be better to reverse the check on codec_dai
and returned early in order to be easier to understand.

Fixes: de2c6f9 ("ASoC: soc-compress: prevent the potentially use of null pointer")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Jiasheng Jiang <[email protected]>
Reviewed-by: Charles Keepax <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
JiangJias authored and broonie committed Mar 14, 2022
1 parent 8fc2622 commit ccb4214
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sound/soc/soc-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,19 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
return -EINVAL;
}

/* check client and interface hw capabilities */
if (codec_dai) {
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
playback = 1;
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE))
capture = 1;
if (!codec_dai) {
dev_err(rtd->card->dev, "Missing codec\n");
return -EINVAL;
}

/* check client and interface hw capabilities */
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
playback = 1;
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE))
capture = 1;

/*
* Compress devices are unidirectional so only one of the directions
* should be set, check for that (xor)
Expand Down

0 comments on commit ccb4214

Please sign in to comment.