drivers/dma: handle sysfs errors
authorJeff Garzik <jeff@garzik.org>
Thu, 8 Mar 2007 17:57:34 +0000 (09:57 -0800)
committerDan Williams <dan.j.williams@intel.com>
Wed, 11 Jul 2007 22:39:03 +0000 (15:39 -0700)
From: Jeff Garzik <jeff@garzik.org>

Signed-off-by: Jeff Garzik <jeff@garzik.org>
Signed-off-by: Chris Leech <christopher.leech@intel.com>
drivers/dma/dmaengine.c

index 322ee2984e3d0108302764832fabce469dfaeb4c..828310d8be80abec05bc00ec1e3bff135ee0c130 100644 (file)
@@ -316,7 +316,7 @@ EXPORT_SYMBOL(dma_async_client_chan_request);
 int dma_async_device_register(struct dma_device *device)
 {
        static int id;
-       int chancnt = 0;
+       int chancnt = 0, rc;
        struct dma_chan* chan;
 
        if (!device)
@@ -338,8 +338,15 @@ int dma_async_device_register(struct dma_device *device)
                snprintf(chan->class_dev.class_id, BUS_ID_SIZE, "dma%dchan%d",
                         device->dev_id, chan->chan_id);
 
+               rc = class_device_register(&chan->class_dev);
+               if (rc) {
+                       chancnt--;
+                       free_percpu(chan->local);
+                       chan->local = NULL;
+                       goto err_out;
+               }
+
                kref_get(&device->refcount);
-               class_device_register(&chan->class_dev);
        }
 
        mutex_lock(&dma_list_mutex);
@@ -349,6 +356,17 @@ int dma_async_device_register(struct dma_device *device)
        dma_chans_rebalance();
 
        return 0;
+
+err_out:
+       list_for_each_entry(chan, &device->channels, device_node) {
+               if (chan->local == NULL)
+                       continue;
+               kref_put(&device->refcount, dma_async_device_cleanup);
+               class_device_unregister(&chan->class_dev);
+               chancnt--;
+               free_percpu(chan->local);
+       }
+       return rc;
 }
 EXPORT_SYMBOL(dma_async_device_register);