Skip to contentSkip to conversation

DMAENGINE: too many kref_put calls

PATCH In review Shannon Nelson 3 participants 3 messages Oct 27, 2007 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DMAENGINE: too many kref_put calls

When a channel is removed from dmaengine, too many kref_put() calls are made and the device removal happens too soon, usually causing a panic.

Cc Haavard Skinnemoen <[email protected]>
Cc Dan Williams <[email protected]>

---

 drivers/dma/dmaengine.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/dma/dmaengine.c +1 -2
index 84257f7..245da53 100644
@@ -134,8 +134,7 @@ static void dma_async_device_cleanup(struct kref *kref);
 
 static void dma_dev_release(struct device *dev)
 {
-	struct dma_chan *chan = to_dma_chan(dev);
-	kref_put(&chan->device->refcount, dma_async_device_cleanup);
+	return;
 }
 
 static struct class dma_devclass = {
#1 lore raw

drivers/dma/dmaengine.c static void dma_async_device_cleanup(struct kref *kref); · line 138

Quoted 6 lines · Shannon Nelson

static void dma_dev_release(struct device *dev)
{

drivers/dma/dmaengine.c +1 -2
-	struct dma_chan *chan = to_dma_chan(dev);
-	kref_put(&chan->device->refcount, dma_async_device_cleanup);
+	return;
 }

Practically guaranteed to be broken. Empty ->release() is almost certain to mean that you can get operations on already freed object.

#2 lore raw
In reply to Shannon Nelson

drivers/dma/dmaengine.c static void dma_async_device_cleanup(struct kref · line 138

Quoted 8 lines · On Fri, 26 Oct 2007 16:56:48 -0700 Shannon Nelson <[email protected]>…
drivers/dma/dmaengine.c +1 -2
@@ -134,8 +134,7 @@ static void dma_async_device_cleanup(struct kref
 *kref); 
 static void dma_dev_release(struct device *dev)
 {
-	struct dma_chan *chan = to_dma_chan(dev);
-	kref_put(&chan->device->refcount, dma_async_device_cleanup);
+	return;
 }

Hmm...what prevents dma_chan_cleanup() from being called while someone still holds a reference to the "class" device? This will allow the module removal to proceed, the device to be freed, and things will blow up...

I think my patch is better. By taking two references, the order in which the cleanup functions are called doesn't matter -- both have to complete before the module removal is allowed to proceed.

Håvard