Module Name:    src
Committed By:   martin
Date:           Sun Nov  4 11:08:10 UTC 2018

Modified Files:
        src/sys/dev/usb [netbsd-8]: uhub.c usb_subr.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1078):

        sys/dev/usb/uhub.c: revision 1.140
        sys/dev/usb/uhub.c: revision 1.141
        sys/dev/usb/usb_subr.c: revision 1.228

Make USB port numbers display consistent

Make sure USB ports numbers are displayed with the first one as number one
and not number zero when rescanning bus. The change makes the display
consistent with the display at boot time USB discovery.

While we are there, make port iteration consistent everywhere in the code,
always starting at one instead of zero.

 -

Make USB port iteration code consistent, always startint at port #1
This complements change in revision 1.140


To generate a diff of this commit:
cvs rdiff -u -r1.136.2.2 -r1.136.2.3 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.220.2.5 -r1.220.2.6 src/sys/dev/usb/usb_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.136.2.2 src/sys/dev/usb/uhub.c:1.136.2.3
--- src/sys/dev/usb/uhub.c:1.136.2.2	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/uhub.c	Sun Nov  4 11:08:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.136.2.2 2018/09/27 14:52:26 martin Exp $	*/
+/*	$NetBSD: uhub.c,v 1.136.2.3 2018/11/04 11:08:10 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.136.2.2 2018/09/27 14:52:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.136.2.3 2018/11/04 11:08:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -412,11 +412,11 @@ uhub_attach(device_t parent, device_t se
 			     sizeof(struct usbd_tt), KM_SLEEP);
 	}
 	/* Set up data structures */
-	for (p = 0; p < nports; p++) {
-		struct usbd_port *up = &hub->uh_ports[p];
+	for (p = 1; p <= nports; p++) {
+		struct usbd_port *up = &hub->uh_ports[p - 1];
 		up->up_dev = NULL;
 		up->up_parent = dev;
-		up->up_portno = p + 1;
+		up->up_portno = p;
 		if (dev->ud_selfpowered)
 			/* Self powered hub, give ports maximum current. */
 			up->up_power = USB_MAX_POWER;
@@ -425,7 +425,7 @@ uhub_attach(device_t parent, device_t se
 		up->up_restartcnt = 0;
 		up->up_reattach = 0;
 		if (UHUB_IS_HIGH_SPEED(sc)) {
-			up->up_tt = &tts[UHUB_IS_SINGLE_TT(sc) ? 0 : p];
+			up->up_tt = &tts[UHUB_IS_SINGLE_TT(sc) ? 0 : p - 1];
 			up->up_tt->utt_hub = hub;
 		} else {
 			up->up_tt = NULL;
@@ -822,8 +822,8 @@ uhub_detach(device_t self, int flags)
 	KERNEL_LOCK(1, curlwp);
 
 	nports = hub->uh_hubdesc.bNbrPorts;
-	for (port = 0; port < nports; port++) {
-		rup = &hub->uh_ports[port];
+	for (port = 1; port <= nports; port++) {
+		rup = &hub->uh_ports[port - 1];
 		if (rup->up_dev == NULL)
 			continue;
 		if ((rc = usb_disconnect_port(rup, self, flags)) != 0) {
@@ -870,8 +870,8 @@ uhub_rescan(device_t self, const char *i
 	struct usbd_device *dev;
 	int port;
 
-	for (port = 0; port < hub->uh_hubdesc.bNbrPorts; port++) {
-		dev = hub->uh_ports[port].up_dev;
+	for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
+		dev = hub->uh_ports[port - 1].up_dev;
 		if (dev == NULL)
 			continue;
 		usbd_reattach_device(sc->sc_dev, dev, port, locators);
@@ -895,8 +895,8 @@ uhub_childdet(device_t self, device_t ch
 		panic("hub not fully initialised, but child deleted?");
 
 	nports = devhub->ud_hub->uh_hubdesc.bNbrPorts;
-	for (port = 0; port < nports; port++) {
-		dev = devhub->ud_hub->uh_ports[port].up_dev;
+	for (port = 1; port <= nports; port++) {
+		dev = devhub->ud_hub->uh_ports[port - 1].up_dev;
 		if (!dev || dev->ud_subdevlen == 0)
 			continue;
 		for (i = 0; i < dev->ud_subdevlen; i++) {

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.220.2.5 src/sys/dev/usb/usb_subr.c:1.220.2.6
--- src/sys/dev/usb/usb_subr.c:1.220.2.5	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/usb_subr.c	Sun Nov  4 11:08:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.220.2.5 2018/09/27 14:52:26 martin Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.220.2.6 2018/11/04 11:08:10 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.5 2018/09/27 14:52:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.6 2018/11/04 11:08:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1230,9 +1230,10 @@ usbd_new_device(device_t parent, struct 
 	     adev = hub, hub = hub->ud_myhub)
 		;
 	if (hub) {
-		for (p = 0; p < hub->ud_hub->uh_hubdesc.bNbrPorts; p++) {
-			if (hub->ud_hub->uh_ports[p].up_dev == adev) {
-				dev->ud_myhsport = &hub->ud_hub->uh_ports[p];
+		for (p = 1; p <= hub->ud_hub->uh_hubdesc.bNbrPorts; p++) {
+			if (hub->ud_hub->uh_ports[p - 1].up_dev == adev) {
+				dev->ud_myhsport =
+				    &hub->ud_hub->uh_ports[p - 1];
 				goto found;
 			}
 		}
@@ -1558,8 +1559,8 @@ usbd_fill_deviceinfo(struct usbd_device 
 	}
 
 	const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
-	for (i = 0; i < __arraycount(di->udi_ports) && i < nports; i++) {
-		p = &dev->ud_hub->uh_ports[i];
+	for (i = 1; i <= __arraycount(di->udi_ports) && i <= nports; i++) {
+		p = &dev->ud_hub->uh_ports[i - 1];
 		if (p->up_dev)
 			err = p->up_dev->ud_addr;
 		else {
@@ -1581,7 +1582,7 @@ usbd_fill_deviceinfo(struct usbd_device 
 			else
 				err = USB_PORT_DISABLED;
 		}
-		di->udi_ports[i] = err;
+		di->udi_ports[i - 1] = err;
 	}
 	di->udi_nports = nports;
 }
@@ -1633,9 +1634,9 @@ usbd_fill_deviceinfo_old(struct usbd_dev
 	}
 
 	const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
-	for (i = 0; i < __arraycount(di->udi_ports) && i < nports;
+	for (i = 1; i <= __arraycount(di->udi_ports) && i <= nports;
 	     i++) {
-		p = &dev->ud_hub->uh_ports[i];
+		p = &dev->ud_hub->uh_ports[i - 1];
 		if (p->up_dev)
 			err = p->up_dev->ud_addr;
 		else {
@@ -1649,7 +1650,7 @@ usbd_fill_deviceinfo_old(struct usbd_dev
 			else
 				err = USB_PORT_DISABLED;
 		}
-		di->udi_ports[i] = err;
+		di->udi_ports[i - 1] = err;
 	}
 	di->udi_nports = nports;
 }

Reply via email to