dmaengine: fsl-edma: fix eDMAv4 channel allocation issue
[platform/kernel/linux-starfive.git] / drivers / dma / stm32-dma.c
index 0b30151..9840594 100644 (file)
@@ -1249,8 +1249,8 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
        enum dma_slave_buswidth max_width;
        struct stm32_dma_desc *desc;
        size_t xfer_count, offset;
-       u32 num_sgs, best_burst, dma_burst, threshold;
-       int i;
+       u32 num_sgs, best_burst, threshold;
+       int dma_burst, i;
 
        num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
        desc = kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT);
@@ -1268,6 +1268,10 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
                best_burst = stm32_dma_get_best_burst(len, STM32_DMA_MAX_BURST,
                                                      threshold, max_width);
                dma_burst = stm32_dma_get_burst(chan, best_burst);
+               if (dma_burst < 0) {
+                       kfree(desc);
+                       return NULL;
+               }
 
                stm32_dma_clear_reg(&desc->sg_req[i].chan_reg);
                desc->sg_req[i].chan_reg.dma_scr =