Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Only call uhci_free_stds if there are TDs to free.



details:   https://anonhg.NetBSD.org/src/rev/df67c4c99453
branches:  trunk
changeset: 825432:df67c4c99453
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Jul 14 10:37:05 2017 +0000

description:
Only call uhci_free_stds if there are TDs to free.

In uhci_alloc_std_chain ensure we fill the TD array correctly and note
the number of allocated TDs so that uhci_free_stds will do the right thing

Fixes a problem seen by anon

diffstat:

 sys/dev/usb/uhci.c |  28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diffs (82 lines):

diff -r 3ead05963686 -r df67c4c99453 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c        Fri Jul 14 06:33:26 2017 +0000
+++ b/sys/dev/usb/uhci.c        Fri Jul 14 10:37:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci.c,v 1.275 2017/06/01 02:45:12 chs Exp $   */
+/*     $NetBSD: uhci.c,v 1.276 2017/07/14 10:37:05 skrll Exp $ */
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.275 2017/06/01 02:45:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.276 2017/07/14 10:37:05 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1995,7 +1995,6 @@
 
        uxfer->ux_stds = NULL;
        uxfer->ux_nstd = ntd;
-       p = NULL;
        if (ntd == 0) {
                *sp = NULL;
                DPRINTF("ntd=0", 0, 0, 0, 0);
@@ -2004,11 +2003,13 @@
        uxfer->ux_stds = kmem_alloc(sizeof(uhci_soft_td_t *) * ntd,
            KM_SLEEP);
 
-       ntd--;
-       for (int i = ntd; i >= 0; i--) {
+       for (int i = 0; i < ntd; i++) {
                p = uhci_alloc_std(sc);
                if (p == NULL) {
-                       uhci_free_stds(sc, uxfer);
+                       if (i != 0) {
+                               uxfer->ux_nstd = i;
+                               uhci_free_stds(sc, uxfer);
+                       }
                        kmem_free(uxfer->ux_stds,
                            sizeof(uhci_soft_td_t *) * ntd);
                        return ENOMEM;
@@ -2212,9 +2213,10 @@
 
        KASSERT(ux->ux_type == UX_BULK);
 
-       uhci_free_stds(sc, ux);
-       if (ux->ux_nstd)
+       if (ux->ux_nstd) {
+               uhci_free_stds(sc, ux);
                kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+       }
 }
 
 usbd_status
@@ -2482,9 +2484,10 @@
 
        KASSERT(ux->ux_type == UX_CTRL);
 
-       uhci_free_stds(sc, ux);
-       if (ux->ux_nstd)
+       if (ux->ux_nstd) {
+               uhci_free_stds(sc, ux);
                kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+       }
 }
 
 usbd_status
@@ -2687,9 +2690,10 @@
 
        KASSERT(ux->ux_type == UX_INTR);
 
-       uhci_free_stds(sc, ux);
-       if (ux->ux_nstd)
+       if (ux->ux_nstd) {
+               uhci_free_stds(sc, ux);
                kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+       }
 }
 
 usbd_status



Home | Main Index | Thread Index | Old Index