From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 431EBC433F5 for ; Thu, 14 Apr 2022 15:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245304AbiDNPKW (ORCPT ); Thu, 14 Apr 2022 11:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346944AbiDNN6I (ORCPT ); Thu, 14 Apr 2022 09:58:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EFA9B53D5; Thu, 14 Apr 2022 06:48:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8365A61D7C; Thu, 14 Apr 2022 13:48:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 940F0C385A5; Thu, 14 Apr 2022 13:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649944095; bh=gUdxT1VasgA5XAo/uD+/ZVGLVxk2Cwn+6TvEB2RMvbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cJC3iclbGGf/Lji9/QHoLkrotlyGsWYZ2FVwGeehBO3HyTvJBLmaZAeia8fHeFatU vNE/ZuXldxXW0gBe9WkIzX8lT3qEoMpVYufu9aGbS9EKI0HIti8jBzBTA46ww30jmI 69LiTI/TfKV6nntE81fio/ZqNGHkq0opM9U1izMU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Dan Carpenter , Jiasheng Jiang , Charles Keepax , Mark Brown Subject: [PATCH 5.4 352/475] ASoC: soc-compress: Change the check for codec_dai Date: Thu, 14 Apr 2022 15:12:17 +0200 Message-Id: <20220414110904.932524310@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110855.141582785@linuxfoundation.org> References: <20220414110855.141582785@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiasheng Jiang 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 Reported-by: Dan Carpenter Signed-off-by: Jiasheng Jiang Reviewed-by: Charles Keepax Link: https://lore.kernel.org/r/20220310030041.1556323-1-jiasheng@iscas.ac.cn Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- 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)