]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.4/spi-spi-topcliff-pch-fix-to-handle-empty-dma-buffers.patch
drop drm-rockchip-shutdown-drm-subsystem-on-shutdown.patch from 4.4.y and 4.9.y
[thirdparty/kernel/stable-queue.git] / queue-4.4 / spi-spi-topcliff-pch-fix-to-handle-empty-dma-buffers.patch
CommitLineData
1143c684
SL
1From 05ad9b5a6b0c285e486b9b9a6fc8e8a0b5836ac4 Mon Sep 17 00:00:00 2001
2From: Aditya Pakki <pakki001@umn.edu>
3Date: Wed, 13 Mar 2019 11:55:41 -0500
4Subject: spi : spi-topcliff-pch: Fix to handle empty DMA buffers
5
6[ Upstream commit f37d8e67f39e6d3eaf4cc5471e8a3d21209843c6 ]
7
8pch_alloc_dma_buf allocated tx, rx DMA buffers which can fail. Further,
9these buffers are used without a check. The patch checks for these
10failures and sends the error upstream.
11
12Signed-off-by: Aditya Pakki <pakki001@umn.edu>
13Signed-off-by: Mark Brown <broonie@kernel.org>
14Signed-off-by: Sasha Levin <sashal@kernel.org>
15---
16 drivers/spi/spi-topcliff-pch.c | 15 +++++++++++++--
17 1 file changed, 13 insertions(+), 2 deletions(-)
18
19diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
20index 93dfcee0f987b..9f30a4ab2004a 100644
21--- a/drivers/spi/spi-topcliff-pch.c
22+++ b/drivers/spi/spi-topcliff-pch.c
23@@ -1326,18 +1326,27 @@ static void pch_free_dma_buf(struct pch_spi_board_data *board_dat,
24 return;
25 }
26
27-static void pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
28+static int pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
29 struct pch_spi_data *data)
30 {
31 struct pch_spi_dma_ctrl *dma;
32+ int ret;
33
34 dma = &data->dma;
35+ ret = 0;
36 /* Get Consistent memory for Tx DMA */
37 dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
38 PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL);
39+ if (!dma->tx_buf_virt)
40+ ret = -ENOMEM;
41+
42 /* Get Consistent memory for Rx DMA */
43 dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
44 PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL);
45+ if (!dma->rx_buf_virt)
46+ ret = -ENOMEM;
47+
48+ return ret;
49 }
50
51 static int pch_spi_pd_probe(struct platform_device *plat_dev)
52@@ -1414,7 +1423,9 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
53
54 if (use_dma) {
55 dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
56- pch_alloc_dma_buf(board_dat, data);
57+ ret = pch_alloc_dma_buf(board_dat, data);
58+ if (ret)
59+ goto err_spi_register_master;
60 }
61
62 ret = spi_register_master(master);
63--
642.20.1
65