Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Don't leak memory if ohci_alloc_std_chain fails.



details:   https://anonhg.NetBSD.org/src/rev/b2c7924946ff
branches:  trunk
changeset: 785863:b2c7924946ff
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Apr 03 19:02:12 2013 +0000

description:
Don't leak memory if ohci_alloc_std_chain fails.

diffstat:

 sys/dev/usb/ohci.c |  23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diffs (78 lines):

diff -r b76902456d4e -r b2c7924946ff sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Wed Apr 03 17:32:24 2013 +0000
+++ b/sys/dev/usb/ohci.c        Wed Apr 03 19:02:12 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.235 2013/03/22 13:28:11 skrll Exp $ */
+/*     $NetBSD: ohci.c,v 1.236 2013/04/03 19:02:12 skrll Exp $ */
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.235 2013/03/22 13:28:11 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.236 2013/04/03 19:02:12 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -98,10 +98,8 @@
 Static ohci_soft_itd_t *ohci_alloc_sitd(ohci_softc_t *);
 Static void            ohci_free_sitd(ohci_softc_t *,ohci_soft_itd_t *);
 
-#if 0
 Static void            ohci_free_std_chain(ohci_softc_t *, ohci_soft_td_t *,
                                            ohci_soft_td_t *);
-#endif
 Static usbd_status     ohci_alloc_std_chain(struct ohci_pipe *,
                            ohci_softc_t *, int, int, usbd_xfer_handle,
                            ohci_soft_td_t *, ohci_soft_td_t **);
@@ -565,11 +563,13 @@
        return (USBD_NORMAL_COMPLETION);
 
  nomem:
-       /* XXX free chain */
+
+       /* Don't free sp - let the caller do that */
+       ohci_free_std_chain(sc, sp->nexttd, NULL);
+
        return (USBD_NOMEM);
 }
 
-#if 0
 Static void
 ohci_free_std_chain(ohci_softc_t *sc, ohci_soft_td_t *std,
                    ohci_soft_td_t *stdend)
@@ -581,7 +581,6 @@
                ohci_free_std(sc, std);
        }
 }
-#endif
 
 ohci_soft_itd_t *
 ohci_alloc_sitd(ohci_softc_t *sc)
@@ -1757,9 +1756,12 @@
 
                err = ohci_alloc_std_chain(opipe, sc, len, isread, xfer,
                          std, &stat);
+               if (err) {
+                       /* stat is unchanged if error */
+                       goto bad3;
+               }
                stat = stat->nexttd; /* point at free TD */
-               if (err)
-                       goto bad3;
+
                /* Start toggle at 1 and then use the carried toggle. */
                std->td.td_flags &= HTOO32(~OHCI_TD_TOGGLE_MASK);
                std->td.td_flags |= HTOO32(OHCI_TD_TOGGLE_1);
@@ -3044,6 +3046,9 @@
        data = opipe->tail.td;
        err = ohci_alloc_std_chain(opipe, sc, len, isread, xfer,
                  data, &tail);
+       if (err)
+               return err;
+       
        /* We want interrupt at the end of the transfer. */
        tail->td.td_flags &= HTOO32(~OHCI_TD_INTR_MASK);
        tail->td.td_flags |= HTOO32(OHCI_TD_SET_DI(1));



Home | Main Index | Thread Index | Old Index