From owner-svn-src-head@FreeBSD.ORG  Sat Nov 13 19:25:11 2010
Return-Path: <owner-svn-src-head@FreeBSD.ORG>
Delivered-To: svn-src-head@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B5655106572F;
	Sat, 13 Nov 2010 19:25:11 +0000 (UTC)
	(envelope-from hselasky@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 896088FC15;
	Sat, 13 Nov 2010 19:25:11 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oADJPBTH057415;
	Sat, 13 Nov 2010 19:25:11 GMT
	(envelope-from hselasky@svn.freebsd.org)
Received: (from hselasky@localhost)
	by svn.freebsd.org (8.14.3/8.14.3/Submit) id oADJPBUY057412;
	Sat, 13 Nov 2010 19:25:11 GMT
	(envelope-from hselasky@svn.freebsd.org)
Message-Id: <201011131925.oADJPBUY057412@svn.freebsd.org>
From: Hans Petter Selasky <hselasky@FreeBSD.org>
Date: Sat, 13 Nov 2010 19:25:11 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-head@freebsd.org
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r215253 - head/lib/libusb
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
	<svn-src-head.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>,
	<mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>,
	<mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Nov 2010 19:25:11 -0000

Author: hselasky
Date: Sat Nov 13 19:25:11 2010
New Revision: 215253
URL: http://svn.freebsd.org/changeset/base/215253

Log:
  Fix LibUSB v1.0 compliancy.
  
  1) We need to allow the USB callback to free the USB transfer itself.
  2) The USB transfer buffer should only be automatically freed when
  freeing the USB transfer.
  
  Fixed by:	hselasky
  Submitted by:	Gustau Perez i Querol
  Approved by:	thompsa (mentor)

Modified:
  head/lib/libusb/libusb10.c
  head/lib/libusb/libusb10_io.c

Modified: head/lib/libusb/libusb10.c
==============================================================================
--- head/lib/libusb/libusb10.c	Sat Nov 13 18:39:24 2010	(r215252)
+++ head/lib/libusb/libusb10.c	Sat Nov 13 19:25:11 2010	(r215253)
@@ -800,6 +800,10 @@ libusb_free_transfer(struct libusb_trans
 	if (uxfer == NULL)
 		return;			/* be NULL safe */
 
+	/* check if we should free the transfer buffer */
+	if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER)
+		free(uxfer->buffer);
+
 	sxfer = (struct libusb_super_transfer *)(
 	    (uint8_t *)uxfer - sizeof(*sxfer));
 

Modified: head/lib/libusb/libusb10_io.c
==============================================================================
--- head/lib/libusb/libusb10_io.c	Sat Nov 13 18:39:24 2010	(r215252)
+++ head/lib/libusb/libusb10_io.c	Sat Nov 13 19:25:11 2010	(r215253)
@@ -187,6 +187,8 @@ do_done:
 	/* Do all done callbacks */
 
 	while ((sxfer = TAILQ_FIRST(&ctx->tr_done))) {
+		uint8_t flags;
+
 		TAILQ_REMOVE(&ctx->tr_done, sxfer, entry);
 		sxfer->entry.tqe_prev = NULL;
 
@@ -197,13 +199,14 @@ do_done:
 		uxfer = (struct libusb_transfer *)(
 		    ((uint8_t *)sxfer) + sizeof(*sxfer));
 
+		/* Allow the callback to free the transfer itself. */
+		flags = uxfer->flags;
+
 		if (uxfer->callback != NULL)
 			(uxfer->callback) (uxfer);
 
-		if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER)
-			free(uxfer->buffer);
-
-		if (uxfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER)
+		/* Check if the USB transfer should be automatically freed. */
+		if (flags & LIBUSB_TRANSFER_FREE_TRANSFER)
 			libusb_free_transfer(uxfer);
 
 		CTX_LOCK(ctx);