From: "Michael Richardson" <mcr@sandelman.ottawa.on.ca>
To: mochel@digitalimplant.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] device_shutdown can loop if the driver frees itself
Date: Wed, 04 Jan 2006 15:31:54 -0500 [thread overview]
Message-ID: <7655.1136406714@sandelman.ottawa.on.ca> (raw)
[-- Attachment #1: Type: text/plain, Size: 2443 bytes --]
This patch changes device_shutdown() to use a newly introduce safe
reverse list traversal. We experienced loops on system reboot if we had
removed and re-inserted our device from the device list.
We noticed this problem on PPC405. Our PCI IDE device comes and goes a lot.
Our hypothesis was that there was a loop caused by the driver->shutdown
freeing memory. It is possible that we do something wrong as well, but
being unable to reboot is kind of nasty.
Signed-off-by: Michael Richardson <mcr@marajade.sandelman.ca>
---
drivers/base/power/shutdown.c | 4 ++--
include/linux/list.h | 13 +++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
applies-to: 96a0b5842e24d6736c698cdbd820a3ad9d8d9f10
49291875d63ec697510fc4cc9a1766b7400ee2d3
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index f50a08b..3a417c8 100644
--- a/drivers/base/power/shutdown.c
+++ b/drivers/base/power/shutdown.c
@@ -35,10 +35,10 @@ extern int sysdev_shutdown(void);
*/
void device_shutdown(void)
{
- struct device * dev;
+ struct device * dev, *devn;
down_write(&devices_subsys.rwsem);
- list_for_each_entry_reverse(dev, &devices_subsys.kset.list,
+ list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list,
kobj.entry) {
if (dev->driver && dev->driver->shutdown) {
dev_dbg(dev, "shutdown\n");
diff --git a/include/linux/list.h b/include/linux/list.h
index 8e33882..b31ec32 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -436,6 +436,19 @@ static inline void list_splice_init(stru
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/**
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop counter.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_entry((head)->prev, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
+/**
* list_for_each_rcu - iterate over an rcu-protected list
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
---
0.99.9.GIT
[-- Attachment #2: Type: application/pgp-signature, Size: 480 bytes --]
next reply other threads:[~2006-01-05 14:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-04 20:31 Michael Richardson [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-01-13 19:50 [PATCH] Remove usb gadget generic driver methods Greg KH
2006-01-13 19:50 ` [PATCH] device_shutdown can loop if the driver frees itself 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=7655.1136406714@sandelman.ottawa.on.ca \
--to=mcr@sandelman.ottawa.on.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@digitalimplant.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