Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Tue, 17 Mar 2009
 09:10:31 -0700
Received: from psmtp.com ([64.18.0.90]) by mail.onstor.com with Microsoft
 SMTPSVC(6.0.3790.3959);	 Tue, 17 Mar 2009 09:10:30 -0700
Received: from source ([213.58.128.207]) by exprod5mx267.postini.com
 ([64.18.4.13]) with SMTP;	Tue, 17 Mar 2009 08:10:30 PST
Received: from localhost.localdomain ([127.0.0.1]:5804 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP	id S21367623AbZCQQKJ
 (ORCPT <rfc822;andy.sharp@onstor.com>);	Tue, 17 Mar 2009 16:10:09 +0000
Received: with ECARTIS (v1.0.0; list linux-mips); Tue, 17 Mar 2009 16:09:52
 +0000 (GMT)
Received: from mba.ocn.ne.jp ([122.1.235.107]:37853 "HELO smtp.mba.ocn.ne.jp")
	by ftp.linux-mips.org with SMTP id S21369100AbZCQQJp convert rfc822-to-8bit
	(ORCPT <rfc822;linux-mips@linux-mips.org>);	Tue, 17 Mar 2009 16:09:45 +0000
Received: from localhost (p3110-ipad206funabasi.chiba.ocn.ne.jp
 [222.145.77.110])	by smtp.mba.ocn.ne.jp (Postfix) with ESMTP	id 51961A9DF;
 Wed, 18 Mar 2009 01:09:37 +0900 (JST)
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
To: "dan.j.williams@intel.com" <dan.j.williams@intel.com>
CC: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	"ralf@linux-mips.org" <ralf@linux-mips.org>, "linux-kernel@vger.kernel.org"
	<linux-kernel@vger.kernel.org>, "haavard.skinnemoen@atmel.com"
	<haavard.skinnemoen@atmel.com>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Tue, 17 Mar 2009 09:09:39 -0700
Subject: Re: [PATCH 1/2] dmaengine: TXx9 Soc DMA Controller driver
Thread-Topic: [PATCH 1/2] dmaengine: TXx9 Soc DMA Controller driver
Thread-Index: AcmnGuVABSGY9dNhQ8SzcuOuR7R8mA==
Message-ID: <20090318.010939.128619068.anemo@mba.ocn.ne.jp>
References: <1237240246.27945.6.camel@dwillia2-linux.ch.intel.com>
	<20090317.112019.147212126.nemoto@toshiba-tops.co.jp>
	<e9c3a7c20903162152w6b73b4b8hba8004e7b349c447@mail.gmail.com>
In-Reply-To: <e9c3a7c20903162152w6b73b4b8hba8004e7b349c447@mail.gmail.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 17 Mar 2009 16:10:30.0687 (UTC)
 FILETIME=[E4D432F0:01C9A71A]
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:99.90000/99.90000 CV: 8.2367 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-neptune: 0/0/0.00/0
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
x-ems-stamp: E2ntj4ddEb3gSZN+zhv6KA==
x-list: linux-mips
x-archive-position: 22091
x-ecartis-version: Ecartis v1.0.0
x-original-sender: anemo@mba.ocn.ne.jp
x-fingerprint: 6ACA 1623 39BD 9A94 9B1A  B746 CA77 FE94 2874 D52F
x-pgp-public-key: http://wwwkeys.pgp.net/pks/lookup?op=get&search=0x2874D52F
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

On Mon, 16 Mar 2009 21:52:10 -0700, Dan Williams <dan.j.williams@intel.com>=
 wrote:
> > Hmm.. why idr_ref is dynamically allocated? =A0Just putting it in
> > dma_device makes thing more simple, no?
>=20
> The sysfs device has a longer lifetime than dma_device.  See commit
> 41d5e59c [1].

The sysfs device for dma_chan (dma_chan_dev) has a shorter lifetime
than dma_device, doesn't it?

I mean something like this (only compile tested):
------------------------------------------------------
Subject: dmaengine: Add idr_ref to dma_device

This fixes memory leak on some error path.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 280a9d2..0708931 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -153,7 +153,6 @@ static void chan_dev_release(struct device *dev)
 		mutex_lock(&dma_list_mutex);
 		idr_remove(&dma_idr, chan_dev->dev_id);
 		mutex_unlock(&dma_list_mutex);
-		kfree(chan_dev->idr_ref);
 	}
 	kfree(chan_dev);
 }
@@ -610,7 +609,6 @@ int dma_async_device_register(struct dma_device *device=
)
 {
 	int chancnt =3D 0, rc;
 	struct dma_chan* chan;
-	atomic_t *idr_ref;
=20
 	if (!device)
 		return -ENODEV;
@@ -637,10 +635,7 @@ int dma_async_device_register(struct dma_device *devic=
e)
 	BUG_ON(!device->device_issue_pending);
 	BUG_ON(!device->dev);
=20
-	idr_ref =3D kmalloc(sizeof(*idr_ref), GFP_KERNEL);
-	if (!idr_ref)
-		return -ENOMEM;
-	atomic_set(idr_ref, 0);
+	atomic_set(&device->idr_ref, 0);
  idr_retry:
 	if (!idr_pre_get(&dma_idr, GFP_KERNEL))
 		return -ENOMEM;
@@ -667,9 +662,9 @@ int dma_async_device_register(struct dma_device *device=
)
 		chan->dev->device.class =3D &dma_devclass;
 		chan->dev->device.parent =3D device->dev;
 		chan->dev->chan =3D chan;
-		chan->dev->idr_ref =3D idr_ref;
+		chan->dev->idr_ref =3D &device->idr_ref;
 		chan->dev->dev_id =3D device->dev_id;
-		atomic_inc(idr_ref);
+		atomic_inc(&device->idr_ref);
 		dev_set_name(&chan->dev->device, "dma%dchan%d",
 			     device->dev_id, chan->chan_id);
=20
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 1956c8d..9e99d82 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -234,6 +234,7 @@ struct dma_device {
=20
 	int dev_id;
 	struct device *dev;
+	atomic_t idr_ref;
=20
 	int (*device_alloc_chan_resources)(struct dma_chan *chan);
 	void (*device_free_chan_resources)(struct dma_chan *chan);

