* [PATCH] dma: xilinx-vdma: add some sanity checks
@ 2016-06-13 15:07 Arnd Bergmann
2016-06-13 17:02 ` Vinod Koul
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-06-13 15:07 UTC (permalink / raw)
To: Vinod Koul
Cc: Arnd Bergmann, Dan Williams, Michal Simek, Sören Brinkmann,
Kedareswara rao Appana, Laurent Pinchart, dmaengine,
linux-arm-kernel, linux-kernel
The newly added xilinx_dma_prep_dma_cyclic function sometimes causes
a gcc warning about the use of the segment function in case
we never run into the inner loop of the function:
dma/xilinx/xilinx_vdma.c: In function 'xilinx_dma_prep_dma_cyclic':
dma/xilinx/xilinx_vdma.c:1808:23: error: 'segment' may be used uninitialized in this function [-Werror=maybe-uninitialized]
segment->hw.control |= XILINX_DMA_BD_SOP;
This can only happen if the period len is zero (which would cause other
problems earlier), or if the buffer is shorter than a period. Neither
of them should ever happen, but by adding an explicit check for these two
cases, we can abort in a more controlled way, and the compiler is
able to see that we never use uninitialized data.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/dma/xilinx/xilinx_vdma.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/dma/xilinx/xilinx_vdma.c b/drivers/dma/xilinx/xilinx_vdma.c
index 0f5b38a0e46f..2ac3253bc823 100644
--- a/drivers/dma/xilinx/xilinx_vdma.c
+++ b/drivers/dma/xilinx/xilinx_vdma.c
@@ -1745,8 +1745,14 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic(
int i;
u32 reg;
+ if (!period_len)
+ return NULL;
+
num_periods = buf_len / period_len;
+ if (!num_periods)
+ return NULL;
+
if (!is_slave_direction(direction))
return NULL;
--
2.7.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] dma: xilinx-vdma: add some sanity checks
2016-06-13 15:07 [PATCH] dma: xilinx-vdma: add some sanity checks Arnd Bergmann
@ 2016-06-13 17:02 ` Vinod Koul
0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2016-06-13 17:02 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Dan Williams, Michal Simek, Sören Brinkmann,
Kedareswara rao Appana, Laurent Pinchart, dmaengine,
linux-arm-kernel, linux-kernel
On Mon, Jun 13, 2016 at 05:07:33PM +0200, Arnd Bergmann wrote:
> The newly added xilinx_dma_prep_dma_cyclic function sometimes causes
> a gcc warning about the use of the segment function in case
> we never run into the inner loop of the function:
>
> dma/xilinx/xilinx_vdma.c: In function 'xilinx_dma_prep_dma_cyclic':
> dma/xilinx/xilinx_vdma.c:1808:23: error: 'segment' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> segment->hw.control |= XILINX_DMA_BD_SOP;
>
> This can only happen if the period len is zero (which would cause other
> problems earlier), or if the buffer is shorter than a period. Neither
> of them should ever happen, but by adding an explicit check for these two
> cases, we can abort in a more controlled way, and the compiler is
> able to see that we never use uninitialized data.
Applied after fixing subsystem name
Thanks
--
~Vinod
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-13 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-13 15:07 [PATCH] dma: xilinx-vdma: add some sanity checks Arnd Bergmann
2016-06-13 17:02 ` Vinod Koul
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).