linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "M'boumba Cedric Madianga" <cedric.madianga@gmail.com>
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" <cedric.madianga@gmail.com>
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	[thread overview]
Message-ID: <1481636451-27863-5-git-send-email-cedric.madianga@gmail.com> (raw)
In-Reply-To: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com>

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 <cedric.madianga@gmail.com>
Reviewed-by: Ludovic BARRE <ludovic.barre@st.com>
---
 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);
-- 
1.9.1

  parent reply	other threads:[~2016-12-13 13:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 13:40 [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 1/9] dmaengine: stm32-dma: Set correct args number for DMA request from DT M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 2/9] dmaengine: stm32-dma: Fix typo in Kconfig M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 3/9] dt-bindings: stm32-dma: Fix typo regarding DMA client binding M'boumba Cedric Madianga
2016-12-13 20:09   ` Rob Herring
2016-12-13 13:40 ` M'boumba Cedric Madianga [this message]
2016-12-13 13:40 ` [PATCH 5/9] dmaengine: stm32-dma: Rework starting transfer management M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 6/9] dmaengine: stm32-dma: Fix residue computation issue in cyclic mode M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 7/9] dmaengine: stm32-dma: Add error messages if xlate fails M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 8/9] dmaengine: stm32-dma: Add synchronization support M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 9/9] dmaengine: stm32-dma: Add max_burst support M'boumba Cedric Madianga
2017-01-02  4:14 ` [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series Vinod Koul
2017-01-02  9:26   ` M'boumba Cedric Madianga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481636451-27863-5-git-send-email-cedric.madianga@gmail.com \
    --to=cedric.madianga@gmail.com \
    --cc=alexandre.torgue@st.com \
    --cc=dan.j.williams@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).