From patchwork Fri Jun 23 12:55:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 9806409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0974660349 for ; Fri, 23 Jun 2017 12:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE2AB21E5A for ; Fri, 23 Jun 2017 12:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2DEF28773; Fri, 23 Jun 2017 12:58:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C4ABF21E5A for ; Fri, 23 Jun 2017 12:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NCjFbsKTtkRCa6a7cldOhtiD2hw+m4dpsQ6NBFMjpdk=; b=rPqNNRV60WKJy2 Pel9AUoTZ647DAslRMU4PaetnWzcWW9EIA8uXVPH+SWN41o+qQE9s1apuyfTmgTWMUXzMWkJvlCwC MCK4CHCnXnqO6Tdd3QFjjHDlFoOuCn4pZR/+3Au++yD5n7Cw4RGfR6QUOiFRHXNvhDEQXW4hQoYhO XIikfX2FVkI1PnSom20pCPeP5NLkwykNigBW5dP8nFH1tC4IFkuQ8NKUx0FqQbX/vhZefNMgvlqwK TKDeSY2Q2ebskcfJF0sTKbq3mpqwzKuvDFIDJDTncBoa5d/Zh7CEUykWmXFDKBEuHTqfkLzeO8KHN BCqvWkkViWSSd2Owfiow==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dOOA5-0001bv-BA; Fri, 23 Jun 2017 12:58:09 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dOO8V-000856-UK for linux-arm-kernel@lists.infradead.org; Fri, 23 Jun 2017 12:56:34 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v5NCrvsk030680; Fri, 23 Jun 2017 14:56:08 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 2b8ckwf3sn-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 23 Jun 2017 14:56:08 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 846AF3F; Fri, 23 Jun 2017 12:56:07 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6140A23F5; Fri, 23 Jun 2017 12:56:07 +0000 (GMT) Received: from localhost (10.201.23.160) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Fri, 23 Jun 2017 14:56:07 +0200 From: Amelie Delaunay To: Mark Brown , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue Subject: [PATCH 8/8] spi: stm32: fix potential dereference null return value Date: Fri, 23 Jun 2017 14:55:50 +0200 Message-ID: <1498222550-19092-9-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498222550-19092-1-git-send-email-amelie.delaunay@st.com> References: <1498222550-19092-1-git-send-email-amelie.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.160] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-23_07:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170623_055632_404532_54FE7D5D X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Amelie Delaunay , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes the usage of rx_dma_desc and tx_dma_desc pointers returned by dmaengine_prep_slave_sg, which can be null. Detected by CoverityScan, CID#1446587 ("Dereference null return value") Reported-by: Colin Ian King Signed-off-by: Amelie Delaunay --- drivers/spi/spi-stm32.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 63af9d9..076a720 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -775,9 +775,6 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, xfer->rx_sg.nents, rx_dma_conf.direction, DMA_PREP_INTERRUPT); - - rx_dma_desc->callback = stm32_spi_dma_cb; - rx_dma_desc->callback_param = spi; } tx_dma_desc = NULL; @@ -790,11 +787,6 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, xfer->tx_sg.nents, tx_dma_conf.direction, DMA_PREP_INTERRUPT); - - if (spi->cur_comm == SPI_SIMPLEX_TX) { - tx_dma_desc->callback = stm32_spi_dma_cb; - tx_dma_desc->callback_param = spi; - } } if ((spi->tx_buf && !tx_dma_desc) || @@ -802,6 +794,9 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, goto dma_desc_error; if (rx_dma_desc) { + rx_dma_desc->callback = stm32_spi_dma_cb; + rx_dma_desc->callback_param = spi; + if (dma_submit_error(dmaengine_submit(rx_dma_desc))) { dev_err(spi->dev, "Rx DMA submit failed\n"); goto dma_desc_error; @@ -811,6 +806,11 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, } if (tx_dma_desc) { + if (spi->cur_comm == SPI_SIMPLEX_TX) { + tx_dma_desc->callback = stm32_spi_dma_cb; + tx_dma_desc->callback_param = spi; + } + if (dma_submit_error(dmaengine_submit(tx_dma_desc))) { dev_err(spi->dev, "Tx DMA submit failed\n"); goto dma_submit_error;