Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Make USB port iteration code consistent, always ...



details:   https://anonhg.NetBSD.org/src/rev/561705375a07
branches:  trunk
changeset: 445327:561705375a07
user:      manu <manu%NetBSD.org@localhost>
date:      Tue Oct 23 01:49:37 2018 +0000

description:
Make USB port iteration code consistent, always startint at port #1

This complements change in revision 1.140

diffstat:

 sys/dev/usb/uhub.c     |  12 ++++++------
 sys/dev/usb/usb_subr.c |  23 ++++++++++++-----------
 2 files changed, 18 insertions(+), 17 deletions(-)

diffs (115 lines):

diff -r 03cc44b7069c -r 561705375a07 sys/dev/usb/uhub.c
--- a/sys/dev/usb/uhub.c        Mon Oct 22 22:36:41 2018 +0000
+++ b/sys/dev/usb/uhub.c        Tue Oct 23 01:49:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhub.c,v 1.140 2018/10/19 00:33:27 manu Exp $  */
+/*     $NetBSD: uhub.c,v 1.141 2018/10/23 01:49:37 manu 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.140 2018/10/19 00:33:27 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.141 2018/10/23 01:49:37 manu Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -413,11 +413,11 @@
                             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;
@@ -426,7 +426,7 @@
                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;
diff -r 03cc44b7069c -r 561705375a07 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Mon Oct 22 22:36:41 2018 +0000
+++ b/sys/dev/usb/usb_subr.c    Tue Oct 23 01:49:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg Exp $       */
+/*     $NetBSD: usb_subr.c,v 1.228 2018/10/23 01:49:37 manu 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.227 2018/09/18 01:36:44 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.228 2018/10/23 01:49:37 manu Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1230,9 +1230,10 @@
             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 @@
        }
 
        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 @@
                        else
                                err = USB_PORT_DISABLED;
                }
-               di->udi_ports[i] = err;
+               di->udi_ports[i - 1] = err;
        }
        di->udi_nports = nports;
 }
@@ -1633,9 +1634,9 @@
        }
 
        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 @@
                        else
                                err = USB_PORT_DISABLED;
                }
-               di->udi_ports[i] = err;
+               di->udi_ports[i - 1] = err;
        }
        di->udi_nports = nports;
 }



Home | Main Index | Thread Index | Old Index