Skip to content

Commit db6a3d0

Browse files
mitaVinod Koul
authored andcommitted
dmaengine: xilinx: avoid memory corruption for device_prep_dma_memcpy()
The device_prep_dma_memcpy() callback for this driver allocates a new xilinx_dma_tx_descriptor whose TX segments list is initialized as empty, but then gets invalid TX segment pointer by list_last_entry() from the empty TX segments list and memory corruption happens by the attempt to update the next descriptor in invalid TX segment pointer. This removes unnecessary memory access for nonexistent tail TX segment which causes memory corruption. Cc: Vinod Koul <vinod.koul@intel.com> Cc: Kedareswara rao Appana <appana.durga.rao@xilinx.com> Cc: Michal Simek <monstr@monstr.eu> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 676f9c2 commit db6a3d0

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

‎drivers/dma/xilinx/xilinx_dma.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst,
16611661
{
16621662
struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
16631663
struct xilinx_dma_tx_descriptor *desc;
1664-
struct xilinx_cdma_tx_segment *segment, *prev;
1664+
struct xilinx_cdma_tx_segment *segment;
16651665
struct xilinx_cdma_desc_hw *hw;
16661666

16671667
if (!len || len > XILINX_DMA_MAX_TRANS_LEN)
@@ -1688,21 +1688,11 @@ xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst,
16881688
hw->dest_addr_msb = upper_32_bits(dma_dst);
16891689
}
16901690

1691-
/* Fill the previous next descriptor with current */
1692-
prev = list_last_entry(&desc->segments,
1693-
struct xilinx_cdma_tx_segment, node);
1694-
prev->hw.next_desc = segment->phys;
1695-
16961691
/* Insert the segment into the descriptor segments list. */
16971692
list_add_tail(&segment->node, &desc->segments);
16981693

1699-
prev = segment;
1700-
1701-
/* Link the last hardware descriptor with the first. */
1702-
segment = list_first_entry(&desc->segments,
1703-
struct xilinx_cdma_tx_segment, node);
17041694
desc->async_tx.phys = segment->phys;
1705-
prev->hw.next_desc = segment->phys;
1695+
hw->next_desc = segment->phys;
17061696

17071697
return &desc->async_tx;
17081698

0 commit comments

Comments
 (0)