Rename comedi_buf_free_page_list() to __comedi_buff_free() and move the
vunmap() of the prealloc_buf and the test for the buf_page_list into
that function.

This gets all the asynchronous buffer deallocation code into one place.

Signed-off-by: H Hartley Sweeten <[email protected]>
Cc: Ian Abbott <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/comedi/comedi_buf.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/comedi_buf.c 
b/drivers/staging/comedi/comedi_buf.c
index cab496b..a21a309 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -28,14 +28,23 @@
 #define COMEDI_PAGE_PROTECTION PAGE_KERNEL
 #endif
 
-static void comedi_buf_free_page_list(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     unsigned n_pages)
+static void __comedi_buf_free(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             unsigned n_pages)
 {
        struct comedi_async *async = s->async;
        struct comedi_buf_page *buf;
        unsigned i;
 
+       if (async->prealloc_buf) {
+               vunmap(async->prealloc_buf);
+               async->prealloc_buf = NULL;
+               async->prealloc_bufsz = 0;
+       }
+
+       if (!async->buf_page_list)
+               return;
+
        for (i = 0; i < n_pages; ++i) {
                buf = &async->buf_page_list[i];
                if (buf->virt_addr) {
@@ -110,24 +119,17 @@ int comedi_buf_alloc(struct comedi_device *dev, struct 
comedi_subdevice *s,
        if (async->prealloc_buf && async->prealloc_bufsz == new_size)
                return 0;
 
-       /*  deallocate old buffer */
-       if (async->prealloc_buf) {
-               vunmap(async->prealloc_buf);
-               async->prealloc_buf = NULL;
-               async->prealloc_bufsz = 0;
-       }
-       if (async->buf_page_list)
-               comedi_buf_free_page_list(dev, s, async->n_buf_pages);
+       /* Deallocate old buffer */
+       __comedi_buf_free(dev, s, async->n_buf_pages);
 
-       /*  allocate new buffer */
+       /* Allocate new buffer */
        if (new_size) {
                unsigned n_pages = new_size >> PAGE_SHIFT;
 
                __comedi_buf_alloc(dev, s, n_pages);
                if (!async->prealloc_buf) {
                        /* Allocation failed */
-                       if (async->buf_page_list)
-                               comedi_buf_free_page_list(dev, s, n_pages);
+                       __comedi_buf_free(dev, s, n_pages);
                        return -ENOMEM;
                }
                async->n_buf_pages = n_pages;
-- 
1.8.0

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to