From patchwork Mon Dec 7 11:00:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: M'boumba Cedric Madianga X-Patchwork-Id: 7782561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EDAE79F349 for ; Mon, 7 Dec 2015 11:10:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DD39203F1 for ; Mon, 7 Dec 2015 11:10:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2768B2035D for ; Mon, 7 Dec 2015 11:10:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a5teW-0007gQ-OW; Mon, 07 Dec 2015 11:08:20 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a5tXd-00082k-B6 for linux-arm-kernel@lists.infradead.org; Mon, 07 Dec 2015 11:01:18 +0000 Received: by wmww144 with SMTP id w144so135295158wmw.1 for ; Mon, 07 Dec 2015 03:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=KrZAsjDsLliJ0x+J4geNIsU1qI4EfwEfPfLezMEYwIM=; b=sCehvvDT+zkqaHJdkT+Fi1S46JmYC7289vIaQKuAKdem21dyXTN2vz6hED4e6Is4Ot FEv5pYKVnxhi4LFsVesXMhSNQ9KLzbM+taFLE8Km10rW4gibhHRfPWH5rOu5jj8jvahI 04SNRz7gF6ZOj7efeTGw4vexXcz3uyL4VqrTbdM8VnfgAqZeErv0S+VxDv8J+bMNIjVy wGJSDJa+fQuHpwa92FDKveEUGlP5bsH/gRn/FA4/m0SJ5uAxHfnloIPT5b4q3S4vRaiO S1+8PCyVk1gJG3TDjY8pSzvtE1kExcasn9tKSxQr98Akdgr1qqm+FKvK3p9quzhR/RZu 8zmA== X-Received: by 10.28.54.165 with SMTP id y37mr21806745wmh.55.1449486051151; Mon, 07 Dec 2015 03:00:51 -0800 (PST) Received: from lmenx29w.st.com. ([80.12.39.60]) by smtp.gmail.com with ESMTPSA id q74sm21122208wmd.0.2015.12.07.03.00.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Dec 2015 03:00:50 -0800 (PST) From: M'boumba Cedric Madianga To: vinod.koul@intel.com, dan.j.williams@intel.com, mcoquelin.stm32@gmail.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc Date: Mon, 7 Dec 2015 12:00:28 +0100 Message-Id: <1449486028-29344-1-git-send-email-cedric.madianga@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151207_030114_032910_928516B1 X-CRM114-Status: GOOD ( 12.97 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: M'boumba Cedric Madianga MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 'commit d8b468394fb7 ("dmaengine: Add STM32 DMA driver")' leads to the following Smatch complaint: drivers/dma/stm32-dma.c:562 stm32_dma_issue_pending() error: we previously assumed 'chan->desc' could be null (see line 560) So, this patch fixes the unchecked dereference of chan->desc by returning operation not permitted error when stm32_dma_start_transfer() does not succeed to allocate a virtual channel descriptor. Reported-by: Dan Carpenter Signed-off-by: M'boumba Cedric Madianga --- Changes since v1: Explain what the patch fixes in the title (Vinod) Add Dan as reporter using Reported-by tag (Vinod) --- --- drivers/dma/stm32-dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 12f3a3e..047476a 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -437,7 +437,7 @@ static int stm32_dma_start_transfer(struct stm32_dma_chan *chan) if (!chan->desc) { vdesc = vchan_next_desc(&chan->vchan); if (!vdesc) - return 0; + return -EPERM; chan->desc = to_stm32_dma_desc(vdesc); chan->next_sg = 0; @@ -559,7 +559,7 @@ static void stm32_dma_issue_pending(struct dma_chan *c) if (!chan->busy) { if (vchan_issue_pending(&chan->vchan) && !chan->desc) { ret = stm32_dma_start_transfer(chan); - if ((chan->desc->cyclic) && (!ret)) + if ((!ret) && (chan->desc->cyclic)) stm32_dma_configure_next_sg(chan); } }