Skip to contentSkip to conversation

usbmon: fix tiny race exposed by the fastboot patches

PATCH In review Arjan van de Ven 2 participants 2 messages Sep 13, 2008 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbmon: fix tiny race exposed by the fastboot patches

From: Arjan van de Ven <[email protected]>
Subject: [PATCH] usbmon: fix tiny race exposed by the fastboot patches

usbmon registers the notifier chain, takes the bus lock and then goes to scan the existing devices for hooking up.

unfortunately, if usb_mon gets initialized while USB bus discovery is going on, it's possible that usbmon gets a notifier on one cpu (which runs without USB locks), and the scan is going on and also finds the new bus, resulting in a double sysfs registration, which then produces a WARNING.

Pete Zaitcev did the bug diagnostics on this one

---
 drivers/usb/mon/mon_main.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/usb/mon/mon_main.c +1 -1
index 442d807..5e0ab42 100644
@@ -361,12 +361,12 @@ static int __init mon_init(void)
 	}
 	// MOD_INC_USE_COUNT(which_module?);
 
-	usb_register_notify(&mon_nb);
 
 	mutex_lock(&usb_bus_list_lock);
 	list_for_each_entry (ubus, &usb_bus_list, bus_list) {
 		mon_bus_init(ubus);
 	}
+	usb_register_notify(&mon_nb);
 	mutex_unlock(&usb_bus_list_lock);
 	return 0;
 
Signature · 8 lines
1.5.5.1



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#1 lore raw

drivers/usb/mon/mon_main.c static int __init mon_init(void) · line 370

Quoted 13 lines · Arjan van de Ven

+++ b/drivers/usb/mon/mon_main.c

drivers/usb/mon/mon_main.c +1 -1
@@ -361,12 +361,12 @@ static int __init mon_init(void)
 	}
 	// MOD_INC_USE_COUNT(which_module?);
 
-	usb_register_notify(&mon_nb);
 
 	mutex_lock(&usb_bus_list_lock);
 	list_for_each_entry (ubus, &usb_bus_list, bus_list) {
 		mon_bus_init(ubus);
 	}
+	usb_register_notify(&mon_nb);
 	mutex_unlock(&usb_bus_list_lock);

Looks like the above does not add new deadlocks and does not miss notifications, so ACK.

-- Pete