* [PATCH] add usb_add_bus() function for usb bus list
@ 2010-04-23 5:45 Tomohiro Kusumi
2010-04-23 15:03 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Tomohiro Kusumi @ 2010-04-23 5:45 UTC (permalink / raw)
To: linux-usb, stern, gregkh, linux-kernel
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@jp.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);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] add usb_add_bus() function for usb bus list
2010-04-23 5:45 [PATCH] add usb_add_bus() function for usb bus list Tomohiro Kusumi
@ 2010-04-23 15:03 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2010-04-23 15:03 UTC (permalink / raw)
To: Tomohiro Kusumi; +Cc: linux-usb, stern, linux-kernel
On Fri, Apr 23, 2010 at 02:45:45PM +0900, Tomohiro Kusumi wrote:
> Hi,
>
> This patch makes usbcore driver sort usb bus on the usb_bus_list by busnum when
> registering a new bus instance.
No one should care about this.
> 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.
How does it confuse anyone? (also note that /proc/bus/usb/devices is
not used in modern distros, it's in a different location now.)
Why not fix your tools to report things in the correct order if you
really care about it? The bus number means nothing except a unique id,
it does not matter if things are sorted or not in the debug file.
Actually, in the lsusb-rewrite I am doing, the userspace tool does the
sorting, no need to change the kernel.
So, sorry, I'm not going to accept this change.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-04-23 15:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-23 5:45 [PATCH] add usb_add_bus() function for usb bus list Tomohiro Kusumi
2010-04-23 15:03 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox