[PATCH 07/37] staging: comedi: das1800: introduce das1800_free_dma()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For aesthetics, introduce a helper function to free the DMA channels and
allocated buffers.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/das1800.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index dd46a91..1eb5eab 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -1303,6 +1303,25 @@ static int das1800_init_dma(struct comedi_device *dev,
 	return 0;
 }
 
+static void das1800_free_dma(struct comedi_device *dev)
+{
+	struct das1800_private *devpriv = dev->private;
+	struct das1800_dma_desc *dma;
+	int i;
+
+	if (!devpriv)
+		return;
+
+	for (i = 0; i < 2; i++) {
+		dma = &devpriv->dma_desc[i];
+		if (dma->chan)
+			free_dma(dma->chan);
+		if (dma->virt_addr)
+			dma_free_coherent(NULL, DMA_BUF_SIZE,
+					  dma->virt_addr, dma->hw_addr);
+	}
+}
+
 static int das1800_probe(struct comedi_device *dev)
 {
 	const struct das1800_board *board = dev->board_ptr;
@@ -1514,18 +1533,9 @@ static int das1800_attach(struct comedi_device *dev,
 static void das1800_detach(struct comedi_device *dev)
 {
 	struct das1800_private *devpriv = dev->private;
-	struct das1800_dma_desc *dma;
-	int i;
 
+	das1800_free_dma(dev);
 	if (devpriv) {
-		for (i = 0; i < 2; i++) {
-			dma = &devpriv->dma_desc[i];
-			if (dma->chan)
-				free_dma(dma->chan);
-			if (dma->virt_addr)
-				dma_free_coherent(NULL, DMA_BUF_SIZE,
-						  dma->virt_addr, dma->hw_addr);
-		}
 		kfree(devpriv->fifo_buf);
 		if (devpriv->iobase2)
 			release_region(devpriv->iobase2, DAS1800_SIZE);
-- 
2.0.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux