From: Michael Richardson Date: Mon, 9 Jan 2006 09:04:51 +0000 (-0800) Subject: [PATCH] device_shutdown can loop if the driver frees itself X-Git-Tag: v2.6.16.28-rc1~1523^2 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=9c08a938ce5a3e1c9d5f764dc6ae844cb1af76ff;p=karo-tx-linux.git [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 Cc: Patrick Mochel Cc: David Howells Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c index a47bb74da72b..c2475f3134ea 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");