ChangeSet 1.1165.2.4, 2003/04/23 12:05:40-07:00, david-b@pacbell.net

[PATCH] usb: fix (rare?) disconnect

It's not good to dereference pointers before checking
them for null.  Seen once on a faulty device init,
which I don't think I'd ever seen before "in the wild".
(Caused by some other 2.5.68 strangeness.)


 drivers/usb/core/usb.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)


diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c	Thu Apr 24 16:27:39 2003
+++ b/drivers/usb/core/usb.c	Thu Apr 24 16:27:39 2003
@@ -791,14 +791,22 @@
 void usb_disconnect(struct usb_device **pdev)
 {
 	struct usb_device	*dev = *pdev;
-	struct usb_bus		*bus = dev->bus;
-	struct usb_operations	*ops = bus->op;
+	struct usb_bus		*bus;
+	struct usb_operations	*ops;
 	int			i;
 
 	might_sleep ();
 
-	if (!dev)
+	if (!dev) {
+		pr_debug ("%s nodev\n", __FUNCTION__);
 		return;
+	}
+	bus = dev->bus;
+	if (!bus) {
+		pr_debug ("%s nobus\n", __FUNCTION__);
+		return;
+	}
+	ops = bus->op;
 
 	*pdev = NULL;
 
