From akpm@linux-foundation.org Tue Jun 23 14:50:09 2009 From: akpm@linux-foundation.org Date: Wed, 10 Jun 2009 12:43:02 -0700 Subject: devres: WARN() and return, don't crash on device_del() of uninitialized device To: greg@kroah.com Cc: akpm@linux-foundation.org, benh@kernel.crashing.org, kay.sievers@vrfy.org, tj@kernel.org Message-ID: <200906101943.n5AJh3Qu030728@imap1.linux-foundation.org> From: Benjamin Herrenschmidt I just debugged an obscure crash caused by a device_del() of a all NULL'd out struct device (in usb-serial) and found that a patch like this one would have saved me time (in addition to improved chances of a bug report from users hitting similar driver bugs). [akpm@linux-foundation.org: cleanup] Signed-off-by: Benjamin Herrenschmidt Cc: Kay Sievers Cc: Tejun Heo Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/base/devres.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -428,6 +428,9 @@ int devres_release_all(struct device *de { unsigned long flags; + /* Looks like an uninitialized device structure */ + if (WARN_ON(dev->devres_head.next == NULL)) + return -ENODEV; spin_lock_irqsave(&dev->devres_lock, flags); return release_nodes(dev, dev->devres_head.next, &dev->devres_head, flags);