linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] devres: WARN() and return, don't crash on device_del() of uninitialized device
@ 2009-05-25  6:53 Benjamin Herrenschmidt
  2009-05-26 21:15 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2009-05-25  6:53 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Greg Kroah-Hartman

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).

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

 drivers/base/devres.c |    5 +++++
 1 file changed, 5 insertions(+)

--- linux-work.orig/drivers/base/devres.c	2009-05-25 16:43:46.000000000 +1000
+++ linux-work/drivers/base/devres.c	2009-05-25 16:46:36.000000000 +1000
@@ -428,6 +428,11 @@ int devres_release_all(struct device *de
 {
 	unsigned long flags;
 
+	/* Looks like an uninitialized device structure */
+	if (dev->devres_head.next == NULL) {
+		WARN(1);
+		return -ENODEV;
+	}
 	spin_lock_irqsave(&dev->devres_lock, flags);
 	return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
 			     flags);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] devres: WARN() and return, don't crash on device_del() of uninitialized device
  2009-05-25  6:53 [PATCH] devres: WARN() and return, don't crash on device_del() of uninitialized device Benjamin Herrenschmidt
@ 2009-05-26 21:15 ` Andrew Morton
  2009-05-26 22:23   ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2009-05-26 21:15 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-kernel, greg, Kay Sievers, Tejun Heo

On Mon, 25 May 2009 16:53:31 +1000
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:

> 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).
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> 
>  drivers/base/devres.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> --- linux-work.orig/drivers/base/devres.c	2009-05-25 16:43:46.000000000 +1000
> +++ linux-work/drivers/base/devres.c	2009-05-25 16:46:36.000000000 +1000
> @@ -428,6 +428,11 @@ int devres_release_all(struct device *de
>  {
>  	unsigned long flags;
>  
> +	/* Looks like an uninitialized device structure */
> +	if (dev->devres_head.next == NULL) {
> +		WARN(1);
> +		return -ENODEV;
> +	}
>  	spin_lock_irqsave(&dev->devres_lock, flags);
>  	return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
>  			     flags);

This could be coded a little more neatly as:

	/* Looks like an uninitialized device structure */
	if (WARN_ON(dev->devres_head.next == NULL))
		return -ENODEV;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] devres: WARN() and return, don't crash on device_del() of uninitialized device
  2009-05-26 21:15 ` Andrew Morton
@ 2009-05-26 22:23   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2009-05-26 22:23 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, greg, Kay Sievers, Tejun Heo

On Tue, 2009-05-26 at 14:15 -0700, Andrew Morton wrote:
> 
> This could be coded a little more neatly as:
> 
>         /* Looks like an uninitialized device structure */
>         if (WARN_ON(dev->devres_head.next == NULL))
>                 return -ENODEV;

Oh I didn't know we could do that nowadays...

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-05-26 22:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-25  6:53 [PATCH] devres: WARN() and return, don't crash on device_del() of uninitialized device Benjamin Herrenschmidt
2009-05-26 21:15 ` Andrew Morton
2009-05-26 22:23   ` Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).