public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
To: linux-usb@vger.kernel.org, stern@rowland.harvard.edu,
	gregkh@suse.de, linux-kernel@vger.kernel.org
Subject: [PATCH] add usb_add_bus() function for usb bus list
Date: Fri, 23 Apr 2010 14:45:45 +0900	[thread overview]
Message-ID: <4BD13409.5040003@jp.fujitsu.com> (raw)

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);


             reply	other threads:[~2010-04-23  5:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23  5:45 Tomohiro Kusumi [this message]
2010-04-23 15:03 ` [PATCH] add usb_add_bus() function for usb bus list Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BD13409.5040003@jp.fujitsu.com \
    --to=kusumi.tomohiro@jp.fujitsu.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox