include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / dma / dmatest.c
index db40508..68d58c4 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 #include <linux/wait.h>
 
 static unsigned int test_buf_size = 16384;
@@ -35,9 +36,24 @@ MODULE_PARM_DESC(threads_per_chan,
 
 static unsigned int max_channels;
 module_param(max_channels, uint, S_IRUGO);
-MODULE_PARM_DESC(nr_channels,
+MODULE_PARM_DESC(max_channels,
                "Maximum number of channels to use (default: all)");
 
+static unsigned int iterations;
+module_param(iterations, uint, S_IRUGO);
+MODULE_PARM_DESC(iterations,
+               "Iterations before stopping test (default: infinite)");
+
+static unsigned int xor_sources = 3;
+module_param(xor_sources, uint, S_IRUGO);
+MODULE_PARM_DESC(xor_sources,
+               "Number of xor source buffers (default: 3)");
+
+static unsigned int pq_sources = 3;
+module_param(pq_sources, uint, S_IRUGO);
+MODULE_PARM_DESC(pq_sources,
+               "Number of p+q source buffers (default: 3)");
+
 /*
  * Initialization patterns. All bytes in the source buffer has bit 7
  * set, all bytes in the destination buffer has bit 7 cleared.
@@ -59,8 +75,9 @@ struct dmatest_thread {
        struct list_head        node;
        struct task_struct      *task;
        struct dma_chan         *chan;
-       u8                      *srcbuf;
-       u8                      *dstbuf;
+       u8                      **srcs;
+       u8                      **dsts;
+       enum dma_transaction_type type;
 };
 
 struct dmatest_chan {
@@ -71,7 +88,7 @@ struct dmatest_chan {
 
 /*
  * These are protected by dma_list_mutex since they're only used by
- * the DMA client event callback
+ * the DMA filter function callback
  */
 static LIST_HEAD(dmatest_channels);
 static unsigned int nr_channels;
@@ -80,7 +97,7 @@ static bool dmatest_match_channel(struct dma_chan *chan)
 {
        if (test_channel[0] == '\0')
                return true;
-       return strcmp(dev_name(&chan->dev), test_channel) == 0;
+       return strcmp(dma_chan_name(chan), test_channel) == 0;
 }
 
 static bool dmatest_match_device(struct dma_device *device)
@@ -98,30 +115,37 @@ static unsigned long dmatest_random(void)
        return buf;
 }
 
-static void dmatest_init_srcbuf(u8 *buf, unsigned int start, unsigned int len)
+static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len)
 {
        unsigned int i;
-
-       for (i = 0; i < start; i++)
-               buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
-       for ( ; i < start + len; i++)
-               buf[i] = PATTERN_SRC | PATTERN_COPY
-                       | (~i & PATTERN_COUNT_MASK);;
-       for ( ; i < test_buf_size; i++)
-               buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
+       u8 *buf;
+
+       for (; (buf = *bufs); bufs++) {
+               for (i = 0; i < start; i++)
+                       buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
+               for ( ; i < start + len; i++)
+                       buf[i] = PATTERN_SRC | PATTERN_COPY
+                               | (~i & PATTERN_COUNT_MASK);
+               for ( ; i < test_buf_size; i++)
+                       buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
+               buf++;
+       }
 }
 
-static void dmatest_init_dstbuf(u8 *buf, unsigned int start, unsigned int len)
+static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len)
 {
        unsigned int i;
-
-       for (i = 0; i < start; i++)
-               buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
-       for ( ; i < start + len; i++)
-               buf[i] = PATTERN_DST | PATTERN_OVERWRITE
-                       | (~i & PATTERN_COUNT_MASK);
-       for ( ; i < test_buf_size; i++)
-               buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
+       u8 *buf;
+
+       for (; (buf = *bufs); bufs++) {
+               for (i = 0; i < start; i++)
+                       buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
+               for ( ; i < start + len; i++)
+                       buf[i] = PATTERN_DST | PATTERN_OVERWRITE
+                               | (~i & PATTERN_COUNT_MASK);
+               for ( ; i < test_buf_size; i++)
+                       buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
+       }
 }
 
 static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
@@ -150,23 +174,30 @@ static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
                                thread_name, index, expected, actual);
 }
 
-static unsigned int dmatest_verify(u8 *buf, unsigned int start,
+static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
                unsigned int end, unsigned int counter, u8 pattern,
                bool is_srcbuf)
 {
        unsigned int i;
        unsigned int error_count = 0;
        u8 actual;
-
-       for (i = start; i < end; i++) {
-               actual = buf[i];
-               if (actual != (pattern | (~counter & PATTERN_COUNT_MASK))) {
-                       if (error_count < 32)
-                               dmatest_mismatch(actual, pattern, i, counter,
-                                               is_srcbuf);
-                       error_count++;
+       u8 expected;
+       u8 *buf;
+       unsigned int counter_orig = counter;
+
+       for (; (buf = *bufs); bufs++) {
+               counter = counter_orig;
+               for (i = start; i < end; i++) {
+                       actual = buf[i];
+                       expected = pattern | (~counter & PATTERN_COUNT_MASK);
+                       if (actual != expected) {
+                               if (error_count < 32)
+                                       dmatest_mismatch(actual, pattern, i,
+                                                        counter, is_srcbuf);
+                               error_count++;
+                       }
+                       counter++;
                }
-               counter++;
        }
 
        if (error_count > 32)
@@ -176,12 +207,17 @@ static unsigned int dmatest_verify(u8 *buf, unsigned int start,
        return error_count;
 }
 
+static void dmatest_callback(void *completion)
+{
+       complete(completion);
+}
+
 /*
  * This function repeatedly tests DMA transfers of various lengths and
- * offsets until it is told to exit by kthread_stop(). There may be
- * multiple threads running this function in parallel for a single
- * channel, and there may be multiple channels being tested in
- * parallel.
+ * offsets for a given operation type until it is told to exit by
+ * kthread_stop(). There may be multiple threads running this function
+ * in parallel for a single channel, and there may be multiple channels
+ * being tested in parallel.
  *
  * Before each test, the source and destination buffer is initialized
  * with a known pattern. This pattern is different depending on
@@ -201,35 +237,151 @@ static int dmatest_func(void *data)
        unsigned int            total_tests = 0;
        dma_cookie_t            cookie;
        enum dma_status         status;
+       enum dma_ctrl_flags     flags;
+       u8                      pq_coefs[pq_sources + 1];
        int                     ret;
+       int                     src_cnt;
+       int                     dst_cnt;
+       int                     i;
 
        thread_name = current->comm;
 
        ret = -ENOMEM;
-       thread->srcbuf = kmalloc(test_buf_size, GFP_KERNEL);
-       if (!thread->srcbuf)
-               goto err_srcbuf;
-       thread->dstbuf = kmalloc(test_buf_size, GFP_KERNEL);
-       if (!thread->dstbuf)
-               goto err_dstbuf;
 
        smp_rmb();
        chan = thread->chan;
+       if (thread->type == DMA_MEMCPY)
+               src_cnt = dst_cnt = 1;
+       else if (thread->type == DMA_XOR) {
+               src_cnt = xor_sources | 1; /* force odd to ensure dst = src */
+               dst_cnt = 1;
+       } else if (thread->type == DMA_PQ) {
+               src_cnt = pq_sources | 1; /* force odd to ensure dst = src */
+               dst_cnt = 2;
+               for (i = 0; i < src_cnt; i++)
+                       pq_coefs[i] = 1;
+       } else
+               goto err_srcs;
+
+       thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL);
+       if (!thread->srcs)
+               goto err_srcs;
+       for (i = 0; i < src_cnt; i++) {
+               thread->srcs[i] = kmalloc(test_buf_size, GFP_KERNEL);
+               if (!thread->srcs[i])
+                       goto err_srcbuf;
+       }
+       thread->srcs[i] = NULL;
+
+       thread->dsts = kcalloc(dst_cnt+1, sizeof(u8 *), GFP_KERNEL);
+       if (!thread->dsts)
+               goto err_dsts;
+       for (i = 0; i < dst_cnt; i++) {
+               thread->dsts[i] = kmalloc(test_buf_size, GFP_KERNEL);
+               if (!thread->dsts[i])
+                       goto err_dstbuf;
+       }
+       thread->dsts[i] = NULL;
+
+       set_user_nice(current, 10);
+
+       flags = DMA_CTRL_ACK | DMA_COMPL_SKIP_DEST_UNMAP | DMA_PREP_INTERRUPT;
+
+       while (!kthread_should_stop()
+              && !(iterations && total_tests >= iterations)) {
+               struct dma_device *dev = chan->device;
+               struct dma_async_tx_descriptor *tx = NULL;
+               dma_addr_t dma_srcs[src_cnt];
+               dma_addr_t dma_dsts[dst_cnt];
+               struct completion cmp;
+               unsigned long tmo = msecs_to_jiffies(3000);
+               u8 align = 0;
 
-       while (!kthread_should_stop()) {
                total_tests++;
 
+               /* honor alignment restrictions */
+               if (thread->type == DMA_MEMCPY)
+                       align = dev->copy_align;
+               else if (thread->type == DMA_XOR)
+                       align = dev->xor_align;
+               else if (thread->type == DMA_PQ)
+                       align = dev->pq_align;
+
+               if (1 << align > test_buf_size) {
+                       pr_err("%u-byte buffer too small for %d-byte alignment\n",
+                              test_buf_size, 1 << align);
+                       break;
+               }
+
                len = dmatest_random() % test_buf_size + 1;
+               len = (len >> align) << align;
+               if (!len)
+                       len = 1 << align;
                src_off = dmatest_random() % (test_buf_size - len + 1);
                dst_off = dmatest_random() % (test_buf_size - len + 1);
 
-               dmatest_init_srcbuf(thread->srcbuf, src_off, len);
-               dmatest_init_dstbuf(thread->dstbuf, dst_off, len);
+               src_off = (src_off >> align) << align;
+               dst_off = (dst_off >> align) << align;
+
+               dmatest_init_srcs(thread->srcs, src_off, len);
+               dmatest_init_dsts(thread->dsts, dst_off, len);
+
+               for (i = 0; i < src_cnt; i++) {
+                       u8 *buf = thread->srcs[i] + src_off;
+
+                       dma_srcs[i] = dma_map_single(dev->dev, buf, len,
+                                                    DMA_TO_DEVICE);
+               }
+               /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
+               for (i = 0; i < dst_cnt; i++) {
+                       dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i],
+                                                    test_buf_size,
+                                                    DMA_BIDIRECTIONAL);
+               }
+
+
+               if (thread->type == DMA_MEMCPY)
+                       tx = dev->device_prep_dma_memcpy(chan,
+                                                        dma_dsts[0] + dst_off,
+                                                        dma_srcs[0], len,
+                                                        flags);
+               else if (thread->type == DMA_XOR)
+                       tx = dev->device_prep_dma_xor(chan,
+                                                     dma_dsts[0] + dst_off,
+                                                     dma_srcs, src_cnt,
+                                                     len, flags);
+               else if (thread->type == DMA_PQ) {
+                       dma_addr_t dma_pq[dst_cnt];
+
+                       for (i = 0; i < dst_cnt; i++)
+                               dma_pq[i] = dma_dsts[i] + dst_off;
+                       tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs,
+                                                    src_cnt, pq_coefs,
+                                                    len, flags);
+               }
+
+               if (!tx) {
+                       for (i = 0; i < src_cnt; i++)
+                               dma_unmap_single(dev->dev, dma_srcs[i], len,
+                                                DMA_TO_DEVICE);
+                       for (i = 0; i < dst_cnt; i++)
+                               dma_unmap_single(dev->dev, dma_dsts[i],
+                                                test_buf_size,
+                                                DMA_BIDIRECTIONAL);
+                       pr_warning("%s: #%u: prep error with src_off=0x%x "
+                                       "dst_off=0x%x len=0x%x\n",
+                                       thread_name, total_tests - 1,
+                                       src_off, dst_off, len);
+                       msleep(100);
+                       failed_tests++;
+                       continue;
+               }
+
+               init_completion(&cmp);
+               tx->callback = dmatest_callback;
+               tx->callback_param = &cmp;
+               cookie = tx->tx_submit(tx);
 
-               cookie = dma_async_memcpy_buf_to_buf(chan,
-                               thread->dstbuf + dst_off,
-                               thread->srcbuf + src_off,
-                               len);
                if (dma_submit_error(cookie)) {
                        pr_warning("%s: #%u: submit error %d with src_off=0x%x "
                                        "dst_off=0x%x len=0x%x\n",
@@ -239,41 +391,50 @@ static int dmatest_func(void *data)
                        failed_tests++;
                        continue;
                }
-               dma_async_memcpy_issue_pending(chan);
+               dma_async_issue_pending(chan);
 
-               do {
-                       msleep(1);
-                       status = dma_async_memcpy_complete(
-                                       chan, cookie, NULL, NULL);
-               } while (status == DMA_IN_PROGRESS);
+               tmo = wait_for_completion_timeout(&cmp, tmo);
+               status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
 
-               if (status == DMA_ERROR) {
-                       pr_warning("%s: #%u: error during copy\n",
-                                       thread_name, total_tests - 1);
+               if (tmo == 0) {
+                       pr_warning("%s: #%u: test timed out\n",
+                                  thread_name, total_tests - 1);
+                       failed_tests++;
+                       continue;
+               } else if (status != DMA_SUCCESS) {
+                       pr_warning("%s: #%u: got completion callback,"
+                                  " but status is \'%s\'\n",
+                                  thread_name, total_tests - 1,
+                                  status == DMA_ERROR ? "error" : "in progress");
                        failed_tests++;
                        continue;
                }
 
+               /* Unmap by myself (see DMA_COMPL_SKIP_DEST_UNMAP above) */
+               for (i = 0; i < dst_cnt; i++)
+                       dma_unmap_single(dev->dev, dma_dsts[i], test_buf_size,
+                                        DMA_BIDIRECTIONAL);
+
                error_count = 0;
 
                pr_debug("%s: verifying source buffer...\n", thread_name);
-               error_count += dmatest_verify(thread->srcbuf, 0, src_off,
+               error_count += dmatest_verify(thread->srcs, 0, src_off,
                                0, PATTERN_SRC, true);
-               error_count += dmatest_verify(thread->srcbuf, src_off,
+               error_count += dmatest_verify(thread->srcs, src_off,
                                src_off + len, src_off,
                                PATTERN_SRC | PATTERN_COPY, true);
-               error_count += dmatest_verify(thread->srcbuf, src_off + len,
+               error_count += dmatest_verify(thread->srcs, src_off + len,
                                test_buf_size, src_off + len,
                                PATTERN_SRC, true);
 
                pr_debug("%s: verifying dest buffer...\n",
                                thread->task->comm);
-               error_count += dmatest_verify(thread->dstbuf, 0, dst_off,
+               error_count += dmatest_verify(thread->dsts, 0, dst_off,
                                0, PATTERN_DST, false);
-               error_count += dmatest_verify(thread->dstbuf, dst_off,
+               error_count += dmatest_verify(thread->dsts, dst_off,
                                dst_off + len, src_off,
                                PATTERN_SRC | PATTERN_COPY, false);
-               error_count += dmatest_verify(thread->dstbuf, dst_off + len,
+               error_count += dmatest_verify(thread->dsts, dst_off + len,
                                test_buf_size, dst_off + len,
                                PATTERN_DST, false);
 
@@ -292,12 +453,25 @@ static int dmatest_func(void *data)
        }
 
        ret = 0;
-       kfree(thread->dstbuf);
+       for (i = 0; thread->dsts[i]; i++)
+               kfree(thread->dsts[i]);
 err_dstbuf:
-       kfree(thread->srcbuf);
+       kfree(thread->dsts);
+err_dsts:
+       for (i = 0; thread->srcs[i]; i++)
+               kfree(thread->srcs[i]);
 err_srcbuf:
+       kfree(thread->srcs);
+err_srcs:
        pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",
                        thread_name, total_tests, failed_tests, ret);
+
+       if (iterations > 0)
+               while (!kthread_should_stop()) {
+                       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
+                       interruptible_sleep_on(&wait_dmatest_exit);
+               }
+
        return ret;
 }
 
@@ -317,40 +491,38 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
        kfree(dtc);
 }
 
-static enum dma_state_client dmatest_add_channel(struct dma_chan *chan)
+static int dmatest_add_threads(struct dmatest_chan *dtc, enum dma_transaction_type type)
 {
-       struct dmatest_chan     *dtc;
-       struct dmatest_thread   *thread;
-       unsigned int            i;
-
-       /* Have we already been told about this channel? */
-       list_for_each_entry(dtc, &dmatest_channels, node)
-               if (dtc->chan == chan)
-                       return DMA_DUP;
-
-       dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
-       if (!dtc) {
-               pr_warning("dmatest: No memory for %s\n", dev_name(&chan->dev));
-               return DMA_NAK;
-       }
+       struct dmatest_thread *thread;
+       struct dma_chan *chan = dtc->chan;
+       char *op;
+       unsigned int i;
 
-       dtc->chan = chan;
-       INIT_LIST_HEAD(&dtc->threads);
+       if (type == DMA_MEMCPY)
+               op = "copy";
+       else if (type == DMA_XOR)
+               op = "xor";
+       else if (type == DMA_PQ)
+               op = "pq";
+       else
+               return -EINVAL;
 
        for (i = 0; i < threads_per_chan; i++) {
                thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
                if (!thread) {
-                       pr_warning("dmatest: No memory for %s-test%u\n",
-                                  dev_name(&chan->dev), i);
+                       pr_warning("dmatest: No memory for %s-%s%u\n",
+                                  dma_chan_name(chan), op, i);
+
                        break;
                }
                thread->chan = dtc->chan;
+               thread->type = type;
                smp_wmb();
-               thread->task = kthread_run(dmatest_func, thread, "%s-test%u",
-                               dev_name(&chan->dev), i);
+               thread->task = kthread_run(dmatest_func, thread, "%s-%s%u",
+                               dma_chan_name(chan), op, i);
                if (IS_ERR(thread->task)) {
-                       pr_warning("dmatest: Failed to run thread %s-test%u\n",
-                                       dev_name(&chan->dev), i);
+                       pr_warning("dmatest: Failed to run thread %s-%s%u\n",
+                                       dma_chan_name(chan), op, i);
                        kfree(thread);
                        break;
                }
@@ -360,86 +532,95 @@ static enum dma_state_client dmatest_add_channel(struct dma_chan *chan)
                list_add_tail(&thread->node, &dtc->threads);
        }
 
-       pr_info("dmatest: Started %u threads using %s\n", i, dev_name(&chan->dev));
-
-       list_add_tail(&dtc->node, &dmatest_channels);
-       nr_channels++;
-
-       return DMA_ACK;
+       return i;
 }
 
-static enum dma_state_client dmatest_remove_channel(struct dma_chan *chan)
+static int dmatest_add_channel(struct dma_chan *chan)
 {
-       struct dmatest_chan     *dtc, *_dtc;
+       struct dmatest_chan     *dtc;
+       struct dma_device       *dma_dev = chan->device;
+       unsigned int            thread_count = 0;
+       unsigned int            cnt;
 
-       list_for_each_entry_safe(dtc, _dtc, &dmatest_channels, node) {
-               if (dtc->chan == chan) {
-                       list_del(&dtc->node);
-                       dmatest_cleanup_channel(dtc);
-                       pr_debug("dmatest: lost channel %s\n",
-                                       dev_name(&chan->dev));
-                       return DMA_ACK;
-               }
+       dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
+       if (!dtc) {
+               pr_warning("dmatest: No memory for %s\n", dma_chan_name(chan));
+               return -ENOMEM;
        }
 
-       return DMA_DUP;
-}
+       dtc->chan = chan;
+       INIT_LIST_HEAD(&dtc->threads);
 
-/*
- * Start testing threads as new channels are assigned to us, and kill
- * them when the channels go away.
- *
- * When we unregister the client, all channels are removed so this
- * will also take care of cleaning things up when the module is
- * unloaded.
- */
-static enum dma_state_client
-dmatest_event(struct dma_client *client, struct dma_chan *chan,
-               enum dma_state state)
-{
-       enum dma_state_client   ack = DMA_NAK;
-
-       switch (state) {
-       case DMA_RESOURCE_AVAILABLE:
-               if (!dmatest_match_channel(chan)
-                               || !dmatest_match_device(chan->device))
-                       ack = DMA_DUP;
-               else if (max_channels && nr_channels >= max_channels)
-                       ack = DMA_NAK;
-               else
-                       ack = dmatest_add_channel(chan);
-               break;
-
-       case DMA_RESOURCE_REMOVED:
-               ack = dmatest_remove_channel(chan);
-               break;
-
-       default:
-               pr_info("dmatest: Unhandled event %u (%s)\n",
-                               state, dev_name(&chan->dev));
-               break;
+       if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
+               cnt = dmatest_add_threads(dtc, DMA_MEMCPY);
+               thread_count += cnt > 0 ? cnt : 0;
+       }
+       if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
+               cnt = dmatest_add_threads(dtc, DMA_XOR);
+               thread_count += cnt > 0 ? cnt : 0;
+       }
+       if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
+               cnt = dmatest_add_threads(dtc, DMA_PQ);
+               thread_count += cnt > 0 ?: 0;
        }
 
-       return ack;
+       pr_info("dmatest: Started %u threads using %s\n",
+               thread_count, dma_chan_name(chan));
+
+       list_add_tail(&dtc->node, &dmatest_channels);
+       nr_channels++;
+
+       return 0;
 }
 
-static struct dma_client dmatest_client = {
-       .event_callback = dmatest_event,
-};
+static bool filter(struct dma_chan *chan, void *param)
+{
+       if (!dmatest_match_channel(chan) || !dmatest_match_device(chan->device))
+               return false;
+       else
+               return true;
+}
 
 static int __init dmatest_init(void)
 {
-       dma_cap_set(DMA_MEMCPY, dmatest_client.cap_mask);
-       dma_async_client_register(&dmatest_client);
-       dma_async_client_chan_request(&dmatest_client);
+       dma_cap_mask_t mask;
+       struct dma_chan *chan;
+       int err = 0;
+
+       dma_cap_zero(mask);
+       dma_cap_set(DMA_MEMCPY, mask);
+       for (;;) {
+               chan = dma_request_channel(mask, filter, NULL);
+               if (chan) {
+                       err = dmatest_add_channel(chan);
+                       if (err) {
+                               dma_release_channel(chan);
+                               break; /* add_channel failed, punt */
+                       }
+               } else
+                       break; /* no more channels available */
+               if (max_channels && nr_channels >= max_channels)
+                       break; /* we have all we need */
+       }
 
-       return 0;
+       return err;
 }
-module_init(dmatest_init);
+/* when compiled-in wait for drivers to load first */
+late_initcall(dmatest_init);
 
 static void __exit dmatest_exit(void)
 {
-       dma_async_client_unregister(&dmatest_client);
+       struct dmatest_chan *dtc, *_dtc;
+       struct dma_chan *chan;
+
+       list_for_each_entry_safe(dtc, _dtc, &dmatest_channels, node) {
+               list_del(&dtc->node);
+               chan = dtc->chan;
+               dmatest_cleanup_channel(dtc);
+               pr_debug("dmatest: dropped channel %s\n",
+                        dma_chan_name(chan));
+               dma_release_channel(chan);
+       }
 }
 module_exit(dmatest_exit);