mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
To: "Shannon Nelson" <shannon.nelson@intel.com>
Cc: "Dan Williams" <dan.j.williams@intel.com>,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	Haavard Skinnemoen <hskinnemoen@atmel.com>
Subject: [PATCH] DMA: Fix broken device refcounting
Date: Fri, 26 Oct 2007 18:12:42 +0200	[thread overview]
Message-ID: <1193415162504-git-send-email-hskinnemoen@atmel.com> (raw)

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>
---
I'm not sure if this is the correct way to solve it, but it seems to
work. The remove() function does not hang, which indicates that the
device's reference count does drop all the way to zero on
unregistration, which in turn indicates that it did actually drop
_below_ zero before.

 drivers/dma/dmaengine.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 8248992..302eded 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -397,6 +397,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;
-- 
1.5.2.5


             reply	other threads:[~2007-10-26 16:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 16:12 Haavard Skinnemoen [this message]
2007-10-26 16:36 ` Dan Williams
2007-10-27 13:49   ` Haavard Skinnemoen
2007-10-27 19:12     ` Dan Williams
2007-10-28 19:17       ` Shannon Nelson
2007-10-29 16:02       ` Nelson, Shannon
2007-10-29 16:11         ` Haavard Skinnemoen
2007-10-26 16:59 ` Nelson, Shannon
2007-10-26 17:10 ` Nelson, Shannon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1193415162504-git-send-email-hskinnemoen@atmel.com \
    --to=hskinnemoen@atmel.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shannon.nelson@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®