[PATCH 09/19] staging: comedi: mite: introduce mite_free_dma_descs()

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

 



Introduce a helper function to handle the dma_free_coherent() of
the mite dma descriptors.

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

diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 14b5345..8b0f875 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -371,16 +371,24 @@ struct mite_ring *mite_alloc_ring(struct mite *mite)
 };
 EXPORT_SYMBOL_GPL(mite_alloc_ring);
 
+static void mite_free_dma_descs(struct mite_ring *ring)
+{
+	struct mite_dma_desc *descs = ring->descs;
+
+	if (descs) {
+		dma_free_coherent(ring->hw_dev,
+				  ring->n_links * sizeof(*descs),
+				  descs, ring->dma_addr);
+		ring->descs = NULL;
+		ring->dma_addr = 0;
+		ring->n_links = 0;
+	}
+}
+
 void mite_free_ring(struct mite_ring *ring)
 {
 	if (ring) {
-		if (ring->descs) {
-			dma_free_coherent(ring->hw_dev,
-					  ring->n_links *
-					  sizeof(struct mite_dma_desc),
-					  ring->descs,
-					  ring->dma_addr);
-		}
+		mite_free_dma_descs(ring);
 		put_device(ring->hw_dev);
 		kfree(ring);
 	}
@@ -467,16 +475,7 @@ int mite_buf_change(struct mite_ring *ring,
 	struct comedi_async *async = s->async;
 	unsigned int n_links;
 
-	if (ring->descs) {
-		dma_free_coherent(ring->hw_dev,
-				  ring->n_links *
-				  sizeof(struct mite_dma_desc),
-				  ring->descs,
-				  ring->dma_addr);
-	}
-	ring->descs = NULL;
-	ring->dma_addr = 0;
-	ring->n_links = 0;
+	mite_free_dma_descs(ring);
 
 	if (async->prealloc_bufsz == 0)
 		return 0;
-- 
2.6.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