staging: comedi: mite: introduce mite_free_dma_descs()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 2 May 2016 17:11:42 +0000 (10:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 May 2016 21:11:15 +0000 (14:11 -0700)
Introduce a helper function to handle the dma_free_coherent() of
the mite dma descriptors.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/mite.c

index 14b5345a93571826f4e09ca998e8a55fbbd45d6d..8b0f875972f56c85a3cc6af24cef55011547a1ab 100644 (file)
@@ -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;