* [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] Remove usb gadget generic driver methods
@ 2006-01-13 19:50 Greg KH
2006-01-13 19:50 ` [PATCH] device_shutdown can loop if the driver frees itself Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Greg KH @ 2006-01-13 19:50 UTC (permalink / raw)
To: linux-kernel; +Cc: rmk
[PATCH] Remove usb gadget generic driver methods
USB gadget drivers make no use of these, remove the pointless
comments.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
commit d78967fb035aeb839a047ae69ce5f1ff39288a8d
tree e76337604583e4052b8a685223af1d342f40ad19
parent 4031bbe4bbec6c0fe50412ef7fb43a270b0f29f1
author Russell King <rmk@arm.linux.org.uk> Fri, 06 Jan 2006 11:41:32 +0000
committer Greg Kroah-Hartman <gregkh@suse.de> Fri, 13 Jan 2006 11:26:11 -0800
drivers/usb/gadget/ether.c | 3 ---
drivers/usb/gadget/inode.c | 3 ---
drivers/usb/gadget/serial.c | 3 ---
drivers/usb/gadget/zero.c | 3 ---
4 files changed, 0 insertions(+), 12 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 8f402f8..afc84cf 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2534,9 +2534,6 @@ static struct usb_gadget_driver eth_driv
.driver = {
.name = (char *) shortname,
.owner = THIS_MODULE,
- // .shutdown = ...
- // .suspend = ...
- // .resume = ...
},
};
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index c6c279d..9a4edc5 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1738,9 +1738,6 @@ static struct usb_gadget_driver gadgetfs
.driver = {
.name = (char *) shortname,
- // .shutdown = ...
- // .suspend = ...
- // .resume = ...
},
};
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 2e6926b..ba9acd5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -374,9 +374,6 @@ static struct usb_gadget_driver gs_gadge
.disconnect = gs_disconnect,
.driver = {
.name = GS_SHORT_NAME,
- /* .shutdown = ... */
- /* .suspend = ... */
- /* .resume = ... */
},
};
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6c58636..2fc110d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1303,9 +1303,6 @@ static struct usb_gadget_driver zero_dri
.driver = {
.name = (char *) shortname,
.owner = THIS_MODULE,
- // .shutdown = ...
- // .suspend = ...
- // .resume = ...
},
};
^ 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®