From nobody@FreeBSD.org  Sun Nov  2 23:18:45 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 992D91065679
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Nov 2008 23:18:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 7DD358FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Nov 2008 23:18:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mA2NIjN9031875
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 2 Nov 2008 23:18:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mA2NIjXd031874;
	Sun, 2 Nov 2008 23:18:45 GMT
	(envelope-from nobody)
Message-Id: <200811022318.mA2NIjXd031874@www.freebsd.org>
Date: Sun, 2 Nov 2008 23:18:45 GMT
From: Rene Ladan <r.c.ladan@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: devel/libusb : fix runtime error
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         128549
>Category:       ports
>Synopsis:       devel/libusb : fix runtime error
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 02 23:20:01 UTC 2008
>Closed-Date:    Fri Nov 14 09:52:33 UTC 2008
>Last-Modified:  Fri Nov 14 10:00:11 UTC 2008
>Originator:     Rene Ladan
>Release:        7.0-RELEASE-p5 amd64
>Organization:
>Environment:
FreeBSD self.rene-ladan.nl 7.0-RELEASE-p5 FreeBSD 7.0-RELEASE-p5 #0: Thu Oct  2 15:01:07 CEST 2008     root@self.rene-ladan.nl:/usr/obj/usr/src70/sys/RENE  amd64

>Description:
From the libusb-devel mailing list:

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -ruN /usr/ports/devel/libusb/Makefile ./Makefile
--- /usr/ports/devel/libusb/Makefile	2008-10-13 19:52:01.000000000 +0200
+++ ./Makefile	2008-11-03 00:06:10.000000000 +0100
@@ -7,7 +7,7 @@
 
 PORTNAME=	libusb
 PORTVERSION=	0.1.12
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	devel
 MASTER_SITES=	${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=	${PORTNAME}
diff -ruN /usr/ports/devel/libusb/files/patch-bsd.c ./files/patch-bsd.c
--- /usr/ports/devel/libusb/files/patch-bsd.c	2008-10-13 19:52:01.000000000 +0200
+++ ./files/patch-bsd.c	2008-11-03 00:09:17.000000000 +0100
@@ -1,14 +1,23 @@
---- bsd.c.orig	Sun Jul 30 11:18:07 2006
-+++ bsd.c	Sun Jul 30 11:20:30 2006
+--- bsd.c.orig	2006-03-04 03:52:46.000000000 +0100
++++ bsd.c	2008-11-03 00:08:15.000000000 +0100
 @@ -408,7 +408,7 @@
    /* Ensure the endpoint address is correct */
    ep |= USB_ENDPOINT_IN;
-
+ 
 -  fd = ensure_ep_open(dev, ep, O_RDONLY);
 +  fd = ensure_ep_open(dev, ep, O_RDONLY | O_NONBLOCK);
    if (fd < 0) {
-       if (usb_debug >= 2) {
-  #ifdef __FreeBSD_kernel__
+     if (usb_debug >= 2) {
+ #ifdef __FreeBSD_kernel__
+@@ -477,7 +477,7 @@
+     USB_ERROR_STR(-errno, "error sending control message: %s",
+                   strerror(errno));
+ 
+-  return UGETW(req.ucr_request.wLength);
++  return req.ucr_actlen;
+ }
+ 
+ int usb_os_find_busses(struct usb_bus **busses)
 @@ -623,9 +623,21 @@
  
  int usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
@@ -16,8 +25,7 @@
 -  /* Not yet done, because I haven't needed it. */
 +  int ret;
 +  struct usb_ctl_request ctl_req;
- 
--  USB_ERROR_STR(-ENOSYS, "usb_clear_halt called, unimplemented on BSD");
++
 +  ctl_req.ucr_addr = 0; // Not used for this type of request
 +  ctl_req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
 +  ctl_req.ucr_request.bRequest = UR_CLEAR_FEATURE;
@@ -28,7 +36,8 @@
 +
 +  if ((ret = ioctl(dev->fd, USB_DO_REQUEST, &ctl_req)) < 0)
 +      USB_ERROR_STR(-errno, "clear_halt:  failed for %d", ep);
-+
+ 
+-  USB_ERROR_STR(-ENOSYS, "usb_clear_halt called, unimplemented on BSD");
 +  return ret;
  }
  


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: pav 
State-Changed-When: Fri Nov 14 09:51:02 UTC 2008 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128549 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/128549: commit references a PR
Date: Fri, 14 Nov 2008 09:52:30 +0000 (UTC)

 pav         2008-11-14 09:52:21 UTC
 
   FreeBSD ports repository
 
   Modified files:
     devel/libusb         Makefile 
     devel/libusb/files   patch-bsd.c 
   Log:
   - Fix a runtime failure.  While usb_control_msg is supposed to return the
     actual number of bytes received, the FreeBSD version returns the receiving
     buffer size instead.  Applications inspecting the returned length for error
     checking will fail.  My patch is based on this excerpt from FreeBSDs
     /usr/src/sys/dev/usb/usb.h.
   
   PR:             ports/128549
   Submitted by:   ladan (maintainer)
   
   Revision  Changes    Path
   1.27      +1 -1      ports/devel/libusb/Makefile
   1.11      +17 -8     ports/devel/libusb/files/patch-bsd.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
 >> The current FreeBSD port compiles fine, so does it fail at run-time
 >> for a particular use case?
 
 > Yes, this is a runtime failure. While usb_control_msg is supposed to return
 > the actual number of bytes received, the freebsd version returns the
 > receiving buffer size instead. Applications inspecting the returned length
 > for error checking will fail. My patch is based on this excerpt from
 > FreeBSDs /usr/src/sys/dev/usb/usb.h.
 
 
 The patched port passes 'make'.
