From: Jiasheng Jiang <jiasheng@xxxxxxxxxxx> commit ccb4214f7f2a8b75acf493f31128e464ee1a3536 upstream. It should be better to reverse the check on codec_dai and returned early in order to be easier to understand. Fixes: de2c6f98817f ("ASoC: soc-compress: prevent the potentially use of null pointer") Reported-by: kernel test robot <lkp@xxxxxxxxx> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx> Reviewed-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/20220310030041.1556323-1-jiasheng@xxxxxxxxxxx Signed-off-by: Mark Brown <broonie@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- sound/soc/soc-compress.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -871,16 +871,19 @@ int snd_soc_new_compress(struct snd_soc_ 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) Patches currently in stable-queue which might be from jiasheng@xxxxxxxxxxx are queue-5.4/iommu-ipmmu-vmsa-check-for-error-num-after-setting-m.patch queue-5.4/mtd-onenand-check-for-error-irq.patch queue-5.4/asoc-soc-compress-change-the-check-for-codec_dai.patch queue-5.4/asoc-fsi-add-check-for-clk_enable.patch queue-5.4/mfd-mc13xxx-add-check-for-mc13xxx_irq_request.patch queue-5.4/asoc-soc-compress-prevent-the-potentially-use-of-nul.patch queue-5.4/iio-adc-add-check-for-devm_request_threaded_irq.patch queue-5.4/asoc-atmel_ssc_dai-handle-errors-for-clk_enable.patch queue-5.4/asoc-mxs-saif-handle-errors-for-clk_enable.patch queue-5.4/alsa-spi-add-check-for-clk_enable.patch queue-5.4/power-supply-wm8350-power-add-missing-free-in-free_c.patch queue-5.4/memory-emif-add-check-for-setup_interrupts.patch queue-5.4/soc-qcom-rpmpd-check-for-null-return-of-devm_kcalloc.patch queue-5.4/asoc-ti-davinci-i2s-add-check-for-clk_enable.patch queue-5.4/asoc-wm8350-handle-error-for-wm8350_register_irq.patch queue-5.4/mmc-davinci_mmc-handle-error-for-clk_enable.patch queue-5.4/ray_cs-check-ioremap-return-value.patch queue-5.4/power-supply-wm8350-power-handle-error-for-wm8350_re.patch