Skip to contentSkip to conversation

Fix to khubd oops, hellooo?

PATCH Pete Zaitcev 1 participant 1 message Mar 13, 2001 USB

lore
Share & tools
lore
#0 lore raw

Is my fix to khubd going anywhere? Randy, David? I have an actual, reproducible bug that I need to close. Here's my message to linux-usb-devel with explanations:
http://marc.theaimsgroup.com/?l=linux-usb-devel&m=98411157628404&w=2

-- Pete

drivers/usb/hub.c +9 -2
diff -ur -X ../dontdiff linux-2.4.2-ac12/drivers/usb/hub.c linux-2.4.2-ac12-p3/drivers/usb/hub.c
@@ -357,6 +357,7 @@
 
 	INIT_LIST_HEAD(&hub->event_list);
 	hub->dev = dev;
+	init_MUTEX(&hub->khubd_sem);
 
 	/* Record the new hub's existence */
 	spin_lock_irqsave(&hub_event_lock, flags);
@@ -400,6 +399,9 @@
 
 	spin_unlock_irqrestore(&hub_event_lock, flags);
 
+	down(&hub->khubd_sem);	/* Wait for khubd to leave this hub alone. */
+	up(&hub->khubd_sem);
+
 	if (hub->urb) {
 		usb_unlink_urb(hub->urb);
 		usb_free_urb(hub->urb);
@@ -709,7 +717,7 @@
 		spin_lock_irqsave(&hub_event_lock, flags);
 
 		if (list_empty(&hub_event_list))
-			goto he_unlock;
+			break;
 
 		/* Grab the next entry from the beginning of the list */
 		tmp = hub_event_list.next;
@@ -720,6 +728,7 @@
 		list_del(tmp);
 		INIT_LIST_HEAD(tmp);
 
+		down(&hub->khubd_sem);	/* never blocks, we were on list */
 		spin_unlock_irqrestore(&hub_event_lock, flags);
 
 		if (hub->error) {
@@ -728,6 +737,7 @@
 			if (usb_hub_reset(hub)) {
 				err("error resetting hub %d - disconnecting", dev->devnum);
 				usb_hub_disconnect(dev);
+				up(&hub->khubd_sem);
 				continue;
 			}
 
@@ -742,6 +752,7 @@
 			ret = usb_get_port_status(dev, i + 1, &portsts);
 			if (ret < 0) {
 				err("get_port_status failed (err = %d)", ret);
+				up(&hub->khubd_sem);
 				continue;
 			}
 
@@ -803,9 +814,9 @@
                         	usb_hub_power_on(hub);
 			}
 		}
+		up(&hub->khubd_sem);
         } /* end while (1) */
 
-he_unlock:
 	spin_unlock_irqrestore(&hub_event_lock, flags);
 }
 
drivers/usb/hub.h +2 -0
diff -ur -X ../dontdiff linux-2.4.2-ac12/drivers/usb/hub.h linux-2.4.2-ac12-p3/drivers/usb/hub.h
@@ -134,6 +134,8 @@
 	struct list_head event_list;
 
 	struct usb_hub_descriptor *descriptor;
+
+	struct semaphore khubd_sem;
 };
 
 #endif /* __LINUX_HUB_H */