Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3990404rwe; Mon, 17 Apr 2023 06:35:32 -0700 (PDT) X-Google-Smtp-Source: AKy350aoX5F0otSBMsTMMtsf6kZtDndSYghimNMHeqX8cawgI76tJbBHGnb1zZlK0NM+SekO5Rxa X-Received: by 2002:a05:6a00:84c:b0:63b:79fa:7d2f with SMTP id q12-20020a056a00084c00b0063b79fa7d2fmr13002643pfk.27.1681738532665; Mon, 17 Apr 2023 06:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681738532; cv=none; d=google.com; s=arc-20160816; b=FfPoMpExBgHb103hIpTm7Z9szGmAz3GwbjFRpWjtjFyioCdntItBrBFbk5O2wcFmRH CUM3XPv0oNw8aCHshT9FjiM/yUkFovuBBULxK1U2RZd7LkM4DoXQzL6rQ/NlMpUqN3hN fjM6PiuEzOe11/5jB7AyFHIJQJLfH00+cjUCq1hOHUFvkpI4rKnpkoP20I54n/UZB4+X iHe4sZcmfPvLAlSK3jsscZ8bCrtEm0mNZeHiVvpCM7rpHu4EMd2VHowe2nEcFkqm9EpV SwLqPlukB6k917BdGjSMMZVkseuesiQdmQkHLxiEhbs7BXHK2XVp7ni+canBIOhR9n/I hxDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=N6bIsnc5MXAfFRUtSuxppPFBP/xdGzpnyFSAsJeM4og=; b=xVzcW4vtsiIHigQpCb2vgufLium0CeE7U7Jv5lzgiJO2NGG4IQAxGeZy75mmky64HQ vyMBhttvBULRWd1Kfu821+AqeL0ziiDpXcyW9yGnA6/gkSORTmsBgO8Z7Kx8QU7Ue7Di y9OQFs3jXUAVToiphVQFnm3Bg1HaNXA654uPJQDRz69t4dkDA5DxgYgt/aCV6q1VIzf5 UJ78DlIyFpa/UkofsHq5FJdlmL31pq+8ybs4oF0yJJdc17yJyvuSLfznFIe/6E4yvw0W QWo/XzjKlW2uFqcwx/d6cYPWZEbRXofbFl27cpitplb7g9HzrPFTF1BWMeI9hJ0dewHY 20KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x37-20020a631725000000b0051b32b10af6si11655568pgl.53.2023.04.17.06.35.21; Mon, 17 Apr 2023 06:35:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229959AbjDQNcv (ORCPT + 99 others); Mon, 17 Apr 2023 09:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjDQNcu (ORCPT ); Mon, 17 Apr 2023 09:32:50 -0400 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CA995BB2 for ; Mon, 17 Apr 2023 06:32:48 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 17 Apr 2023 16:32:46 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 17 Apr 2023 16:32:46 +0300 From: Nikita Zhandarovich To: Shengjiu Wang CC: Nikita Zhandarovich , Xiubo Li , Fabio Estevam , Nicolin Chen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , , , , , Natalia Petrova Subject: [PATCH] ASoC: fsl_asrc_dma: fix potential null-ptr-deref Date: Mon, 17 Apr 2023 06:32:42 -0700 Message-ID: <20230417133242.53339-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma_request_slave_channel() may return NULL which will lead to NULL pointer dereference error in 'tmp_chan->private'. Correct this behaviour by, first, switching from deprecated function dma_request_slave_channel() to dma_request_chan(). Secondly, enable sanity check for the resuling value of dma_request_chan(). Also, fix description that follows the enacted changes and that concerns the use of dma_request_slave_channel(). Fixes: 706e2c881158 ("ASoC: fsl_asrc_dma: Reuse the dma channel if available in Back-End") Co-developed-by: Natalia Petrova Signed-off-by: Nikita Zhandarovich --- sound/soc/fsl/fsl_asrc_dma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c index 3b81a465814a..05a7d1588d20 100644 --- a/sound/soc/fsl/fsl_asrc_dma.c +++ b/sound/soc/fsl/fsl_asrc_dma.c @@ -209,14 +209,19 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, be_chan = soc_component_to_pcm(component_be)->chan[substream->stream]; tmp_chan = be_chan; } - if (!tmp_chan) - tmp_chan = dma_request_slave_channel(dev_be, tx ? "tx" : "rx"); + if (!tmp_chan) { + tmp_chan = dma_request_chan(dev_be, tx ? "tx" : "rx"); + if (IS_ERR(tmp_chan)) { + dev_err(dev, "failed to request DMA channel for Back-End\n"); + return -EINVAL; + } + } /* * An EDMA DEV_TO_DEV channel is fixed and bound with DMA event of each * peripheral, unlike SDMA channel that is allocated dynamically. So no * need to configure dma_request and dma_request2, but get dma_chan of - * Back-End device directly via dma_request_slave_channel. + * Back-End device directly via dma_request_chan. */ if (!asrc->use_edma) { /* Get DMA request of Back-End */