Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1541077

[PATCH 4/9] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status

From M'boumba Cedric Madianga <cedric.madianga@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 4/9] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status
Date 2016-12-13 14:50 +0100
Message-ID <sNVCW-1NI-19@gated-at.bofh.it> (permalink)
References <sNVCW-1NI-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 2/9] dmaengine: stm32-dma: Fix typo in Kconfig M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 7/9] dmaengine: stm32-dma: Add error messages if xlate fails M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 4/9] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 3/9] dt-bindings: stm32-dma: Fix typo regarding DMA client binding M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
    Re: [PATCH 3/9] dt-bindings: stm32-dma: Fix typo regarding DMA  client binding Rob Herring <robh@kernel.org> - 2016-12-13 21:20 +0100
  [PATCH 5/9] dmaengine: stm32-dma: Rework starting transfer management M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 1/9] dmaengine: stm32-dma: Set correct args number for DMA request from DT M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  [PATCH 6/9] dmaengine: stm32-dma: Fix residue computation issue in cyclic mode M'boumba Cedric Madianga <cedric.madianga@gmail.com> - 2016-12-13 14:50 +0100
  Re: [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements  series Vinod Koul <vinod.koul@intel.com> - 2017-01-02 05:20 +0100
    Re: [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series "M'boumba Cedric Madianga" <cedric.madianga@gmail.com> - 2017-01-02 10:30 +0100

csiph-web