Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: spi-ti-qspi: Free DMA resources

Release the RX channel and free the dma coherent memory when
devm_spi_register_master() fails.

Fixes: 5720ec0a6d26 ("spi: spi-ti-qspi: Add DMA support for QSPI mmap read")
Cc: stable@vger.kernel.org
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Link: https://lore.kernel.org/r/20210218130950.90155-1-tudor.ambarus@microchip.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Tudor Ambarus and committed by
Mark Brown
1d309cd6 a38fd874

+14 -6
+14 -6
drivers/spi/spi-ti-qspi.c
··· 733 733 return 0; 734 734 } 735 735 736 + static void ti_qspi_dma_cleanup(struct ti_qspi *qspi) 737 + { 738 + if (qspi->rx_bb_addr) 739 + dma_free_coherent(qspi->dev, QSPI_DMA_BUFFER_SIZE, 740 + qspi->rx_bb_addr, 741 + qspi->rx_bb_dma_addr); 742 + 743 + if (qspi->rx_chan) 744 + dma_release_channel(qspi->rx_chan); 745 + } 746 + 736 747 static const struct of_device_id ti_qspi_match[] = { 737 748 {.compatible = "ti,dra7xxx-qspi" }, 738 749 {.compatible = "ti,am4372-qspi" }, ··· 897 886 if (!ret) 898 887 return 0; 899 888 889 + ti_qspi_dma_cleanup(qspi); 890 + 900 891 pm_runtime_disable(&pdev->dev); 901 892 free_master: 902 893 spi_master_put(master); ··· 917 904 pm_runtime_put_sync(&pdev->dev); 918 905 pm_runtime_disable(&pdev->dev); 919 906 920 - if (qspi->rx_bb_addr) 921 - dma_free_coherent(qspi->dev, QSPI_DMA_BUFFER_SIZE, 922 - qspi->rx_bb_addr, 923 - qspi->rx_bb_dma_addr); 924 - if (qspi->rx_chan) 925 - dma_release_channel(qspi->rx_chan); 907 + ti_qspi_dma_cleanup(qspi); 926 908 927 909 return 0; 928 910 }