From patchwork Tue Dec 13 13:40:46 2016 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: 9472305 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 CFF686021C for ; Tue, 13 Dec 2016 13:43:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2A51284AE for ; Tue, 13 Dec 2016 13:43:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B47EE284B8; Tue, 13 Dec 2016 13:43:29 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62F592833C for ; Tue, 13 Dec 2016 13:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933076AbcLMNnM (ORCPT ); Tue, 13 Dec 2016 08:43:12 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:32822 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933024AbcLMNlL (ORCPT ); Tue, 13 Dec 2016 08:41:11 -0500 Received: by mail-wj0-f193.google.com with SMTP id kp2so16597157wjc.0; Tue, 13 Dec 2016 05:41:10 -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:in-reply-to:references; bh=WgX+qbJagzySslupDtyIy0S+DimJj8W22WTZE5cczag=; b=OYv1I5YXrtAR2VqgKyv/ryDWFdON9FBbXopq2qCi8+NWHnTuRJfW3nmXOA2JaId7F1 adEAAXsjdsfLvyyQYX4ArA8BzwJCnTj+b5+BYYany+1q/Jwmzqv00R89WKbUWdz1Hhf7 6l+VPhwQXHOXfIQywlGqisV1WoWPN8+9+UBdsvzFkef0E7NWRCl53kEWtKMcpUbuuqgO 0nzU96iovsAJkv1d1RGqbLQfTczH7WNcwOxZRb/LEwnzDDwCA76RBQUGa02zw7AR+u8n SvvUJgLjV/6qD5aW5ahRrh9LFnMExMn6+C/jowYIKpdp+SU47dBwi0RqOSxVzsGL03UA 4Auw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WgX+qbJagzySslupDtyIy0S+DimJj8W22WTZE5cczag=; b=ikZqKZVzSR85P+mcz46MQTO7abb1yZ2dzbzBbvl8hd3KRSU1nfXqzsad4efuPidNrC LkKVSaCYH+w50/hYweXdfKyB9Fvflhg3M4WNT7uU7uJo0hSGb/Cmp0NFmFeGtsn+aUU6 C6EgIHIyD+miY6orPHKxRRUnrvWR1HFIdicdazyftsYk8pUc9DNZBepJ+EjEj+WeukMJ glXvq+W1uwx6zZLvOmXNBauag3aTZLMkz2pr6yZoDtqZCKFNwuyFa3L7jteiM7ra4kGz mnwzq7BuHYrEI/qgYcANBbR/ZRt5uUCbJp/J15zdrkdow0VVh10fhiNri76nHAeJXGfQ 6r0A== X-Gm-Message-State: AKaTC01Lny12Z82tMefGiKDb319Lr1IjLaQssGSkI2hZQFYvLkyBVteffULUdJkNDtyjpA== X-Received: by 10.194.187.103 with SMTP id fr7mr81610084wjc.99.1481636469764; Tue, 13 Dec 2016 05:41:09 -0800 (PST) Received: from lmenx29w.st.com. ([80.215.199.148]) by smtp.gmail.com with ESMTPSA id vr9sm62269846wjc.35.2016.12.13.05.41.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Dec 2016 05:41:09 -0800 (PST) From: M'boumba Cedric Madianga To: vinod.koul@intel.com, robh+dt@kernel.org, mark.rutland@arm.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, dan.j.williams@intel.com, dmaengine@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: M'boumba Cedric Madianga Subject: [PATCH 4/9] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status Date: Tue, 13 Dec 2016 14:40:46 +0100 Message-Id: <1481636451-27863-5-git-send-email-cedric.madianga@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com> References: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP chan->desc is always set to NULL when a DMA transfer is complete. As a DMA transfer could be complete during the call of stm32_dma_tx_status, we need to be sure that chan->desc is not NULL before using this variable to avoid a null pointer deference issue. Signed-off-by: M'boumba Cedric Madianga Reviewed-by: Ludovic BARRE --- drivers/dma/stm32-dma.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index a884b85..3056ce7 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -880,7 +880,7 @@ static enum dma_status stm32_dma_tx_status(struct dma_chan *c, struct virt_dma_desc *vdesc; enum dma_status status; unsigned long flags; - u32 residue; + u32 residue = 0; status = dma_cookie_status(c, cookie, state); if ((status == DMA_COMPLETE) || (!state)) @@ -888,16 +888,12 @@ static enum dma_status stm32_dma_tx_status(struct dma_chan *c, spin_lock_irqsave(&chan->vchan.lock, flags); vdesc = vchan_find_desc(&chan->vchan, cookie); - if (cookie == chan->desc->vdesc.tx.cookie) { + if (chan->desc && cookie == chan->desc->vdesc.tx.cookie) residue = stm32_dma_desc_residue(chan, chan->desc, chan->next_sg); - } else if (vdesc) { + else if (vdesc) residue = stm32_dma_desc_residue(chan, to_stm32_dma_desc(vdesc), 0); - } else { - residue = 0; - } - dma_set_residue(state, residue); spin_unlock_irqrestore(&chan->vchan.lock, flags);