Re: [PATCH] DMA: Fix broken device refcounting

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Dan Williams
Date: Friday, October 26, 2007 - 9:36 am

On Fri, 2007-10-26 at 09:12 -0700, Haavard Skinnemoen wrote:

Yeah, Shannon ran into this too...  I'd like to be able clean this up by
reducing the number of time we take the device reference, but the
following patch is still showing problems in Shannon's environment, so I
missed one...

---

dmaengine: fix up dma_device refcounting

From: Dan Williams <dan.j.williams@intel.com>

Currently the code drops too many references on the parent device.  Change
the scheme to:

+ take a reference at registration:
  dma_async_device_register()
+ take a reference for each channel device registered:
  device_register(&chan->dev)
- drop a reference for each channel device unregistered:
  device_unregister(&chan->dev)
- drop a reference at unregistration:
  dma_async_device_unregister()

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---

 drivers/dma/dmaengine.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 84257f7..d2b600b 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -186,10 +186,9 @@ static void dma_client_chan_alloc(struct dma_client *client)
 				/* we are done once this client rejects
 				 * an available resource
 				 */
-				if (ack == DMA_ACK) {
+				if (ack == DMA_ACK)
 					dma_chan_get(chan);
-					kref_get(&device->refcount);
-				} else if (ack == DMA_NAK)
+				else if (ack == DMA_NAK)
 					return;
 			}
 		}
@@ -221,7 +220,6 @@ void dma_chan_cleanup(struct kref *kref)
 {
 	struct dma_chan *chan = container_of(kref, struct dma_chan, refcount);
 	chan->device->device_free_chan_resources(chan);
-	kref_put(&chan->device->refcount, dma_async_device_cleanup);
 }
 EXPORT_SYMBOL(dma_chan_cleanup);
 
@@ -276,11 +274,8 @@ static void dma_clients_notify_removed(struct dma_chan *chan)
 		/* client was holding resources for this channel so
 		 * free it
 		 */
-		if (ack == DMA_ACK) {
+		if (ack == DMA_ACK)
 			dma_chan_put(chan);
-			kref_put(&chan->device->refcount,
-				dma_async_device_cleanup);
-		}
 	}
 
 	mutex_unlock(&dma_list_mutex);
@@ -320,11 +315,8 @@ void dma_async_client_unregister(struct dma_client *client)
 			ack = client->event_callback(client, chan,
 				DMA_RESOURCE_REMOVED);
 
-			if (ack == DMA_ACK) {
+			if (ack == DMA_ACK)
 				dma_chan_put(chan);
-				kref_put(&chan->device->refcount,
-					dma_async_device_cleanup);
-			}
 		}
 
 	list_del(&client->global_node);
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] DMA: Fix broken device refcounting, Haavard Skinnemoen, (Fri Oct 26, 9:12 am)
Re: [PATCH] DMA: Fix broken device refcounting, Dan Williams, (Fri Oct 26, 9:36 am)
RE: [PATCH] DMA: Fix broken device refcounting, Nelson, Shannon, (Fri Oct 26, 9:59 am)
Re: [PATCH] DMA: Fix broken device refcounting, Haavard Skinnemoen, (Sat Oct 27, 6:49 am)
Re: [PATCH] DMA: Fix broken device refcounting, Dan Williams, (Sat Oct 27, 12:12 pm)
Re: [PATCH] DMA: Fix broken device refcounting, Shannon Nelson, (Sun Oct 28, 12:17 pm)
RE: [PATCH] DMA: Fix broken device refcounting, Nelson, Shannon, (Mon Oct 29, 9:02 am)
Re: [PATCH] DMA: Fix broken device refcounting, Haavard Skinnemoen, (Mon Oct 29, 9:11 am)