Skip to content

Commit 53a256a

Browse files
l1kvinodkoul
authored andcommitted
dmaengine: Fix access to uninitialized dma_slave_caps
dmaengine_desc_set_reuse() allocates a struct dma_slave_caps on the stack, populates it using dma_get_slave_caps() and then accesses one of its members. However dma_get_slave_caps() may fail and this isn't accounted for, leading to a legitimate warning of gcc-4.9 (but not newer versions): In file included from drivers/spi/spi-bcm2835.c:19:0: drivers/spi/spi-bcm2835.c: In function 'dmaengine_desc_set_reuse': >> include/linux/dmaengine.h:1370:10: warning: 'caps.descriptor_reuse' is used uninitialized in this function [-Wuninitialized] if (caps.descriptor_reuse) { Fix it, thereby also silencing the gcc-4.9 warning. The issue has been present for 4 years but surfaces only now that the first caller of dmaengine_desc_set_reuse() has been added in spi-bcm2835.c. Another user of reusable DMA descriptors has existed for a while in pxa_camera.c, but it sets the DMA_CTRL_REUSE flag directly instead of calling dmaengine_desc_set_reuse(). Nevertheless, tag this commit for stable in case there are out-of-tree users. Fixes: 2724202 ("dmaengine: Add DMA_CTRL_REUSE") Reported-by: kbuild test robot <[email protected]> Signed-off-by: Lukas Wunner <[email protected]> Cc: [email protected] # v4.3+ Link: https://lore.kernel.org/r/ca92998ccc054b4f2bfd60ef3adbab2913171eac.1575546234.git.lukas@wunner.de Signed-off-by: Vinod Koul <[email protected]>
1 parent e42617b commit 53a256a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/linux/dmaengine.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,11 @@ static inline int dma_get_slave_caps(struct dma_chan *chan,
13641364
static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)
13651365
{
13661366
struct dma_slave_caps caps;
1367+
int ret;
13671368

1368-
dma_get_slave_caps(tx->chan, &caps);
1369+
ret = dma_get_slave_caps(tx->chan, &caps);
1370+
if (ret)
1371+
return ret;
13691372

13701373
if (caps.descriptor_reuse) {
13711374
tx->flags |= DMA_CTRL_REUSE;

0 commit comments

Comments
 (0)