All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc
@ 2015-12-07 11:00 ` M'boumba Cedric Madianga
  0 siblings, 0 replies; 4+ messages in thread
From: M'boumba Cedric Madianga @ 2015-12-07 11:00 UTC (permalink / raw)
  To: vinod.koul, dan.j.williams, mcoquelin.stm32, dmaengine,
	linux-arm-kernel, linux-kernel
  Cc: M'boumba Cedric Madianga

'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 <dan.carpenter@oracle.com>
Signed-off-by: M'boumba Cedric Madianga <cedric.madianga@gmail.com>

---
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);
 		}
 	}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc
@ 2015-12-07 11:00 ` M'boumba Cedric Madianga
  0 siblings, 0 replies; 4+ messages in thread
From: M'boumba Cedric Madianga @ 2015-12-07 11:00 UTC (permalink / raw)
  To: linux-arm-kernel

'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 <dan.carpenter@oracle.com>
Signed-off-by: M'boumba Cedric Madianga <cedric.madianga@gmail.com>

---
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);
 		}
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc
  2015-12-07 11:00 ` M'boumba Cedric Madianga
@ 2015-12-10  4:15   ` Vinod Koul
  -1 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2015-12-10  4:15 UTC (permalink / raw)
  To: M'boumba Cedric Madianga
  Cc: dan.j.williams, mcoquelin.stm32, dmaengine, linux-arm-kernel,
	linux-kernel

On Mon, Dec 07, 2015 at 12:00:28PM +0100, M'boumba Cedric Madianga wrote:
> '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.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc
@ 2015-12-10  4:15   ` Vinod Koul
  0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2015-12-10  4:15 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Dec 07, 2015 at 12:00:28PM +0100, M'boumba Cedric Madianga wrote:
> '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.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-10  4:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-07 11:00 [PATCH v2] dmaengine: stm32-dma: Fix unchecked deference of chan->desc M'boumba Cedric Madianga
2015-12-07 11:00 ` M'boumba Cedric Madianga
2015-12-10  4:15 ` Vinod Koul
2015-12-10  4:15   ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.