lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 23 Apr 2010 14:45:45 +0900
From:	Tomohiro Kusumi <kusumi.tomohiro@...fujitsu.com>
To:	linux-usb@...r.kernel.org, stern@...land.harvard.edu,
	gregkh@...e.de, linux-kernel@...r.kernel.org
Subject: [PATCH] add usb_add_bus() function for usb bus list

Hi,

This patch makes usbcore driver sort usb bus on the usb_bus_list by busnum when
registering a new bus instance.

In current implementation a new bus instance is simply added in front of existing busses.
Although there is nothing wrong with it in kernel code, reloading HCD may break bus order
of /proc/bus/usb/devices as it makes usbcore re-register the bus to the list as shown in
the example below. and it doesn't look good or it may confuse some users.

# lsmod | grep hcd
uhci_hcd               19324  0 
ehci_hcd               39109  0 
# grep "Bus=" /proc/bus/usb/devices
T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=1.5 MxCh= 0
T:  Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  3 Spd=12  MxCh= 0
T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  4 Spd=480 MxCh= 4
# rmmod ehci-hcd; modprobe ehci-hcd
# grep "Bus=" /proc/bus/usb/devices
T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  4 Spd=480 MxCh= 4
T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=1.5 MxCh= 0
T:  Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  5 Spd=12  MxCh= 0

With this patch, bus instances on the usb_bus_list is kept in busnum order (from large to
small busnum). As a result /proc/bus/usb/devices prints devices in busnum order regardless
of HCD reloading. Although a few applications (eg.lsusb) use /proc/bus/usb/devices, this
patch has no effect to them.

# lsmod | grep hcd
uhci_hcd               19324  0 
ehci_hcd               39109  0 
# grep "Bus=" /proc/bus/usb/devices
T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=1.5 MxCh= 0
T:  Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  3 Spd=12  MxCh= 0
T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  4 Spd=480 MxCh= 4
# rmmod ehci-hcd; modprobe ehci-hcd
# grep "Bus=" /proc/bus/usb/devices
T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=1.5 MxCh= 0
T:  Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  5 Spd=12  MxCh= 0
T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  4 Spd=480 MxCh= 4

Thanks,
Tomohiro Kusumi




Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@...fujitsu.com>
---

diff -aNur linux-2.6.34-rc5.org/drivers/usb/core/hcd.c linux-2.6.34-rc5/drivers/usb/core/hcd.c
--- linux-2.6.34-rc5.org/drivers/usb/core/hcd.c	2010-04-20 08:29:56.000000000 +0900
+++ linux-2.6.34-rc5/drivers/usb/core/hcd.c	2010-04-23 14:19:50.000000000 +0900
@@ -877,6 +877,23 @@
 /*-------------------------------------------------------------------------*/
 
 /**
+ * usb_add_bus - register the bus to the usb_bus_list,
+ * caller need to hold usb_bus_list_lock
+ * @bus: pointer to the bus to register
+ */
+static void usb_add_bus(struct usb_bus *bus)
+{
+	struct usb_bus *b;
+	list_for_each_entry(b, &usb_bus_list, bus_list) {
+		if (bus->busnum > b->busnum) {
+			list_add_tail(&bus->bus_list, &b->bus_list);
+			return;
+		}
+	}
+	list_add_tail(&bus->bus_list, &usb_bus_list);
+}
+
+/**
  * usb_register_bus - registers the USB host controller with the usb core
  * @bus: pointer to the bus to register
  * Context: !in_interrupt()
@@ -899,7 +916,7 @@
 	bus->busnum = busnum;
 
 	/* Add it to the local list of buses */
-	list_add (&bus->bus_list, &usb_bus_list);
+	usb_add_bus(bus);
 	mutex_unlock(&usb_bus_list_lock);
 
 	usb_notify_add_bus(bus);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ