From: Chuansheng Liu <chuansheng.liu@intel.com>
To: dmitry.torokhov@gmail.com, tj@kernel.org, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, chuansheng.liu@intel.com
Subject: [PATCH] devres: Freeing the drs after all release() are called
Date: Wed, 06 Nov 2013 14:40:18 +0800 [thread overview]
Message-ID: <1383720018.3650.37.camel@cliu38-desktop-build> (raw)
In release_nodes(), it will call dr->node.release() and kfree
dr one by one.
But sometimes the previous dr maybe be used by next .release(),
such as:
[50314.855534] [<c12b172f>] ? synchronize_irq+0x3f/0xb0
[50314.861193] [<c12b18e9>] __free_irq+0x149/0x200
[50314.866367] [<c12b19e3>] free_irq+0x43/0xa0
[50314.871152] [<c12b4864>] devm_irq_release+0x14/0x20
[50314.876713] [<c169e806>] release_nodes+0x136/0x1b0
[50314.882178] [<c169ee79>] devres_release_all+0x39/0x60
[50314.887935] [<c169b411>] __device_release_driver+0x71/0xd0
the free_irq() will sync the last irq handling, which maybe use
freed dr, then it will cause memory corruption.
Here split the dr kfreeing actions after all dr->node.release().
Signed-off-by: Liu, Chuansheng <chuansheng.liu@intel.com>
---
drivers/base/devres.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 507379e..66ff0be 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -490,9 +490,11 @@ static int release_nodes(struct device *dev, struct list_head *first,
list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) {
devres_log(dev, &dr->node, "REL");
dr->node.release(dev, dr->data);
- kfree(dr);
}
+ list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry)
+ kfree(dr);
+
return cnt;
}
--
1.7.9.5
next reply other threads:[~2013-11-06 6:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-06 6:40 Chuansheng Liu [this message]
2013-11-06 8:58 ` Greg KH
2013-11-07 0:27 ` Liu, Chuansheng
2013-11-07 0:29 ` tj
2013-11-07 0:36 ` Liu, Chuansheng
2013-11-07 0:46 ` Dmitry Torokhov
2013-11-07 0:53 ` Liu, Chuansheng
2013-11-07 0:51 ` tj
2013-11-07 1:18 ` Liu, Chuansheng
2013-11-07 1:56 ` Greg KH
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=1383720018.3650.37.camel@cliu38-desktop-build \
--to=chuansheng.liu@intel.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/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®