Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb umidi(4): Clarify loops. No functional change i...



details:   https://anonhg.NetBSD.org/src/rev/a448edb20296
branches:  trunk
changeset: 368245:a448edb20296
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jul 01 01:08:06 2022 +0000

description:
umidi(4): Clarify loops.  No functional change intended.

diffstat:

 sys/dev/usb/umidi.c |  23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)

diffs (69 lines):

diff -r 77b7d54042a3 -r a448edb20296 sys/dev/usb/umidi.c
--- a/sys/dev/usb/umidi.c       Fri Jul 01 01:07:56 2022 +0000
+++ b/sys/dev/usb/umidi.c       Fri Jul 01 01:08:06 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umidi.c,v 1.88 2022/06/27 18:56:56 riastradh Exp $     */
+/*     $NetBSD: umidi.c,v 1.89 2022/07/01 01:08:06 riastradh Exp $     */
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.88 2022/06/27 18:56:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.89 2022/07/01 01:08:06 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -724,8 +724,7 @@
 alloc_all_endpoints(struct umidi_softc *sc)
 {
        usbd_status err;
-       struct umidi_endpoint *ep;
-       int i;
+       int i, n;
 
        if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP)) {
                err = alloc_all_endpoints_fixed_ep(sc);
@@ -737,17 +736,16 @@
        if (err != USBD_NORMAL_COMPLETION)
                return err;
 
-       ep = sc->sc_endpoints;
-       for (i = sc->sc_out_num_endpoints+sc->sc_in_num_endpoints; i > 0; i--) {
-               err = alloc_pipe(ep);
+       n = sc->sc_out_num_endpoints + sc->sc_in_num_endpoints;
+       for (i = 0; i < n; i++) {
+               err = alloc_pipe(&sc->sc_endpoints[i]);
                if (err != USBD_NORMAL_COMPLETION) {
-                       for (; ep != sc->sc_endpoints; ep--)
-                               free_pipe(ep-1);
+                       while (i --> 0)
+                               free_pipe(&sc->sc_endpoints[i]);
                        kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
                        sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
                        break;
                }
-               ep++;
        }
        return err;
 }
@@ -755,14 +753,15 @@
 static void
 free_all_endpoints(struct umidi_softc *sc)
 {
-       int i;
+       int i, n;
 
        if (sc->sc_endpoints == NULL) {
                /* nothing to free */
                return;
        }
 
-       for (i=0; i<sc->sc_in_num_endpoints+sc->sc_out_num_endpoints; i++)
+       n = sc->sc_in_num_endpoints + sc->sc_out_num_endpoints;
+       for (i = 0; i < n; i++)
                free_pipe(&sc->sc_endpoints[i]);
        kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
        sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;



Home | Main Index | Thread Index | Old Index