[PATCH] gpib: fluke: Add some missing dma_unmap_single()

Christophe JAILLET posted 1 patch 1 week, 6 days ago
drivers/gpib/eastwood/fluke_gpib.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
[PATCH] gpib: fluke: Add some missing dma_unmap_single()
Posted by Christophe JAILLET 1 week, 6 days ago
In some error handling paths, a dma_unmap_single() is missing.
Add it to avoid a leak.

Fixes: 55936779f496 ("staging: gpib: Add Fluke cda based cards GPIB driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is compile tested only.
---
 drivers/gpib/eastwood/fluke_gpib.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpib/eastwood/fluke_gpib.c b/drivers/gpib/eastwood/fluke_gpib.c
index 61eca22dc2b0..1ef5c16a81ba 100644
--- a/drivers/gpib/eastwood/fluke_gpib.c
+++ b/drivers/gpib/eastwood/fluke_gpib.c
@@ -454,8 +454,10 @@ static int fluke_dma_write(struct gpib_board *board, u8 *buffer, size_t length,
 		retval = wait_for_sids_or_sgns(board);
 
 	*bytes_written = readl(e_priv->write_transfer_counter) & write_transfer_counter_mask;
-	if (WARN_ON_ONCE(*bytes_written > length))
-		return -EFAULT;
+	if (WARN_ON_ONCE(*bytes_written > length)) {
+		retval = -EFAULT;
+		goto cleanup;
+	}
 
 cleanup:
 	dma_unmap_single(board->dev, address, length, DMA_TO_DEVICE);
@@ -641,8 +643,10 @@ static int fluke_dma_read(struct gpib_board *board, u8 *buffer,
 	 */
 	usleep_range(10, 15);
 	residue = fluke_get_dma_residue(e_priv->dma_channel, dma_cookie);
-	if (WARN_ON_ONCE(residue > length || residue < 0))
+	if (WARN_ON_ONCE(residue > length || residue < 0)) {
+		dma_unmap_single(board->dev, bus_address, length, DMA_FROM_DEVICE);
 		return -EFAULT;
+	}
 	*bytes_read += length - residue;
 	dmaengine_terminate_all(e_priv->dma_channel);
 	// make sure fluke_dma_callback got called
-- 
2.52.0