From patchwork Mon Apr 17 13:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 84257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2145118vqo; Mon, 17 Apr 2023 06:58:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUx5c7OjgW8v6EkLwQ3PmVMKLO6xLR+8zsC/MsB/uCoIEWLQUbhkjso/lg+L/DTri+j4F5 X-Received: by 2002:a05:6a20:4712:b0:cc:5f27:d003 with SMTP id ek18-20020a056a20471200b000cc5f27d003mr12649789pzb.56.1681739938073; Mon, 17 Apr 2023 06:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681739938; cv=none; d=google.com; s=arc-20160816; b=MTuNldQ4EdPiWCxScX3YsZ/vGaIRBkJdFU4g+VPkphHy16fbZTRN1BskOomtWwol2I e+zSIFeMRO85PhhDHm4OY7P1fKM2FcCzyM7pAmPnB+4L1mAUnLdE/WmoM00N9L5QjJWT mWvQppPcRUBQhZrzJ589PtBfR0osDp99rrPVd1WQinSBiGS4iHuAh/HT6gW/btxEk+r/ beHWaGGqah2c0CfHH+VkjE85xFHNKusWsAf7lUs5mTjreIGhoywBXXfni7Wkc5NhTFGc gldHFY4uOKy5+c7AVMZ9rGGE3Rq/SUr6fjZbC/WQYJvSfrhgwApA6eW+mtF7FtWh26qL X16g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v184-20020a6389c1000000b00518543f5bc7si12892626pgd.573.2023.04.17.06.58.43; Mon, 17 Apr 2023 06:58:58 -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 S229926AbjDQNcw (ORCPT + 99 others); Mon, 17 Apr 2023 09:32:52 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763432137207202255?= X-GMAIL-MSGID: =?utf-8?q?1763432137207202255?= 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 */