Module Name:    src
Committed By:   bouyer
Date:           Sat Apr 20 09:52:20 UTC 2013

Modified Files:
        src/sys/dev/usb [netbsd-6]: ohci.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #864):
        sys/dev/usb/ohci.c: revision 1.234
        sys/dev/usb/ohci.c: revision 1.236
Don't leak memory if ohci_alloc_std_chain fails.
When dumping the done list in ohci_softintr / OHCI_DEBUG use the correct
list next pointer.
PR/33450 and part of PR/35379.


To generate a diff of this commit:
cvs rdiff -u -r1.218.8.1 -r1.218.8.2 src/sys/dev/usb/ohci.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/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.218.8.1 src/sys/dev/usb/ohci.c:1.218.8.2
--- src/sys/dev/usb/ohci.c:1.218.8.1	Sat Jan  5 23:30:04 2013
+++ src/sys/dev/usb/ohci.c	Sat Apr 20 09:52:19 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.218.8.1 2013/01/05 23:30:04 riz Exp $	*/
+/*	$NetBSD: ohci.c,v 1.218.8.2 2013/04/20 09:52:19 bouyer Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/ohci.c,v 1.22 1999/11/17 22:33:40 n_hibma Exp $	*/
 
 /*
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.218.8.1 2013/01/05 23:30:04 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.218.8.2 2013/04/20 09:52:19 bouyer Exp $");
 
 #include "opt_usb.h"
 
@@ -100,10 +100,8 @@ Static void		ohci_free_std(ohci_softc_t 
 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 **);
@@ -566,11 +564,13 @@ ohci_alloc_std_chain(struct ohci_pipe *o
 	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)
@@ -582,7 +582,6 @@ ohci_free_std_chain(ohci_softc_t *sc, oh
 		ohci_free_std(sc, std);
 	}
 }
-#endif
 
 ohci_soft_itd_t *
 ohci_alloc_sitd(ohci_softc_t *sc)
@@ -1303,7 +1302,8 @@ ohci_softintr(void *v)
 #ifdef OHCI_DEBUG
 	if (ohcidebug > 10) {
 		DPRINTF(("ohci_process_done: TD done:\n"));
-		ohci_dump_tds(sc, sdone);
+		for (std = sdone; std; std = std->dnext)
+			ohci_dump_td(sc, std);	
 	}
 #endif
 
@@ -1384,7 +1384,8 @@ ohci_softintr(void *v)
 #ifdef OHCI_DEBUG
 	if (ohcidebug > 10) {
 		DPRINTF(("ohci_softintr: ITD done:\n"));
-		ohci_dump_itds(sc, sidone);
+		for (sitd = sidone; sitd; sitd = sitd->dnext)
+			ohci_dump_itd(sc, sitd);	
 	}
 #endif
 
@@ -1716,9 +1717,12 @@ ohci_device_request(usbd_xfer_handle xfe
 
 		err = ohci_alloc_std_chain(opipe, sc, len, isread, xfer,
 			  std, &stat);
-		stat = stat->nexttd; /* point at free TD */
-		if (err)
+		if (err) {
+			/* stat is unchanged if error */
 			goto bad3;
+		}
+		stat = stat->nexttd; /* point at free TD */
+
 		/* 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);
@@ -2970,6 +2974,9 @@ ohci_device_bulk_start(usbd_xfer_handle 
 	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));

Reply via email to