* [PATCH] device_shutdown can loop if the driver frees itself
@ 2006-01-04 20:31 Michael Richardson
0 siblings, 0 replies; 2+ messages in thread
From: Michael Richardson @ 2006-01-04 20:31 UTC (permalink / raw)
To: mochel; +Cc: linux-kernel
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] device_shutdown can loop if the driver frees itself
2006-01-13 19:50 [PATCH] Remove usb gadget generic driver methods Greg KH
@ 2006-01-13 19:50 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2006-01-13 19:50 UTC (permalink / raw)
To: linux-kernel; +Cc: mcr
[PATCH] device_shutdown can loop if the driver frees itself
This patch changes device_shutdown() to use the newly introduced 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>
Cc: Patrick Mochel <mochel@digitalimplant.org>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit 9c08a938ce5a3e1c9d5f764dc6ae844cb1af76ff
tree 9bd0a984b2e5466454e2633783786a516fe14484
parent 2d7b5a70e01ff8b1b054d8313362e454e3057c5a
author Michael Richardson <mcr@sandelman.ottawa.on.ca> Mon, 09 Jan 2006 01:04:51 -0800
committer Greg Kroah-Hartman <gregkh@suse.de> Fri, 13 Jan 2006 11:26:12 -0800
drivers/base/power/shutdown.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index a47bb74..c2475f3 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->bus && dev->bus->shutdown) {
dev_dbg(dev, "shutdown\n");
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-01-13 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-04 20:31 [PATCH] device_shutdown can loop if the driver frees itself Michael Richardson
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
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®