[PATCH 36/37] staging: comedi: das16: introduce das16_free_dma()

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

 



For aesthetics, move the freeing of the DMA channel and the buffers to
a helper function.

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

diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index 0f4a587..e0b41ae 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -1028,6 +1028,24 @@ static int das16_alloc_dma(struct comedi_device *dev, unsigned int dma_chan)
 	return 0;
 }
 
+static void das16_free_dma(struct comedi_device *dev)
+{
+	struct das16_private_struct *devpriv = dev->private;
+	struct das16_dma_desc *dma;
+	int i;
+
+	if (devpriv->timer.data)
+		del_timer_sync(&devpriv->timer);
+	for (i = 0; i < 2; i++) {
+		dma = &devpriv->dma_desc[i];
+		if (dma->virt_addr)
+			pci_free_consistent(NULL, DAS16_DMA_SIZE,
+					    dma->virt_addr, dma->hw_addr);
+	}
+	if (devpriv->dma_chan)
+		free_dma(devpriv->dma_chan);
+}
+
 static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
 	const struct das16_board *board = dev->board_ptr;
@@ -1226,24 +1244,11 @@ static void das16_detach(struct comedi_device *dev)
 {
 	const struct das16_board *board = dev->board_ptr;
 	struct das16_private_struct *devpriv = dev->private;
-	struct das16_dma_desc *dma;
-	int i;
 
 	if (devpriv) {
-		if (devpriv->timer.data)
-			del_timer_sync(&devpriv->timer);
 		if (dev->iobase)
 			das16_reset(dev);
-
-		for (i = 0; i < 2; i++) {
-			dma = &devpriv->dma_desc[i];
-			if (dma->virt_addr)
-				pci_free_consistent(NULL, DAS16_DMA_SIZE,
-						    dma->virt_addr,
-						    dma->hw_addr);
-		}
-		if (devpriv->dma_chan)
-			free_dma(devpriv->dma_chan);
+		das16_free_dma(dev);
 		kfree(devpriv->user_ai_range_table);
 		kfree(devpriv->user_ao_range_table);
 
-- 
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