All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine: Fix broken device refcounting
@ 2007-11-07 18:46 Dan Williams
  2007-11-14 21:45 ` [stable] " Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2007-11-07 18:46 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Shannon Nelson, hskinnemoen, stable

From: Haavard Skinnemoen <hskinnemoen@atmel.com>

When a DMA device is unregistered, its reference count is decremented
twice for each channel: Once dma_class_dev_release() and once in
dma_chan_cleanup(). This may result in the DMA device driver's
remove() function completing before all channels have been cleaned
up, causing lots of use-after-free fun.

Fix it by incrementing the device's reference count twice for each
channel during registration.

Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
[dan.j.williams@intel.com: kill unnecessary client refcounting]
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Shannon Nelson <shannon.nelson@intel.com>
Cc: stable@kernel.org
---

This fixes dmaengine refcounting in 2.6.23.y and 2.6.24-rc.

 drivers/dma/dmaengine.c |   17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 84257f7..ec7e871 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;
 			}
 		}
@@ -276,11 +275,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 +316,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);
@@ -401,6 +394,8 @@ int dma_async_device_register(struct dma_device *device)
 			goto err_out;
 		}
 
+		/* One for the channel, one of the class device */
+		kref_get(&device->refcount);
 		kref_get(&device->refcount);
 		kref_init(&chan->refcount);
 		chan->slow_ref = 0;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [stable] [PATCH] dmaengine: Fix broken device refcounting
  2007-11-07 18:46 [PATCH] dmaengine: Fix broken device refcounting Dan Williams
@ 2007-11-14 21:45 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2007-11-14 21:45 UTC (permalink / raw)
  To: Dan Williams
  Cc: Andrew Morton, Shannon Nelson, linux-kernel, hskinnemoen, stable

On Wed, Nov 07, 2007 at 11:46:07AM -0700, Dan Williams wrote:
> From: Haavard Skinnemoen <hskinnemoen@atmel.com>
> 
> When a DMA device is unregistered, its reference count is decremented
> twice for each channel: Once dma_class_dev_release() and once in
> dma_chan_cleanup(). This may result in the DMA device driver's
> remove() function completing before all channels have been cleaned
> up, causing lots of use-after-free fun.
> 
> Fix it by incrementing the device's reference count twice for each
> channel during registration.
> 
> Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
> [dan.j.williams@intel.com: kill unnecessary client refcounting]
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Shannon Nelson <shannon.nelson@intel.com>
> Cc: stable@kernel.org

I don't see this in Linus's tree yet, right?

When it goes in, can you resend it to the stable@kernel.org people?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-14 21:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-07 18:46 [PATCH] dmaengine: Fix broken device refcounting Dan Williams
2007-11-14 21:45 ` [stable] " Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.