Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jun 2009 19:09:13 GMT
From:      Sylvestre Gallon <syl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 164885 for review
Message-ID:  <200906221909.n5MJ9DnW052270@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=164885

Change 164885 by syl@syl_atuin on 2009/06/22 19:08:13

	- Add endpoint number in test2.
	- Change for a working request in test1 (GET_COMM_FEATURE)
	- Fix Segfault in libusb_proxy and libusb_free_transfer.
	- Some style changes.
	- Fix synchronous callback segfault.
	- Get closer libusb-1.0.2 implementation.

Affected files ...

.. //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test1/test1.c#5 edit
.. //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test2/test2.c#4 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#43 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#16 edit

Differences ...

==== //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test1/test1.c#5 (text+ko) ====

@@ -12,12 +12,12 @@
 {
 	libusb_device *dev;
 	libusb_device_handle *devh;
+	int ret;
 	uint8_t data[2] = {0,0};
 
 	printf("This program will try to issue a GET_STATUS"
 	       " request on the PID_TEST VID_TEST device control endpoint\n");
 
-	
 	if (libusb_init(&ctx) != 0) {
 		fprintf(stderr, "libusb_init_failed\n");
 		return (EXIT_FAILURE);
@@ -26,8 +26,13 @@
 	if ((devh = libusb_open_device_with_vid_pid(ctx, VID_TEST, PID_TEST)) != NULL) {
 		libusb_detach_kernel_driver(devh, 1);
 		dev = libusb_get_device(devh);
-		libusb_control_transfer(devh, 0x80, 0x01, 0x00, 0x00, data, 2, 100000);
-		printf("data = 0x%.2x 0x%.2x\n", data[0], data[1]);
+		ret = libusb_control_transfer(devh, 0xa1, 0x03, 0x00, 0x00, data, 2, 10);
+		printf("end tr\n");
+		if (ret == LIBUSB_TRANSFER_COMPLETED) {
+			printf("data = 0x%.2x 0x%.2x\n", data[0], data[1]);
+		} else {
+			printf("transfer failed with 0x%.8x error code\n", ret);
+		}
 	} else {
 		fprintf(stderr, "\nNo device match or lack of permissions.\n");
 	}

==== //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test2/test2.c#4 (text+ko) ====

@@ -3,8 +3,8 @@
 #include <stdio.h>
 #include <libusb.h>
 
-#define PID_TEST	0x8300
-#define VID_TEST	0x05ac
+#define PID_TEST	0x2303
+#define VID_TEST	0x067b
 #define STR_SIZE	29
 
 libusb_context *ctx;
@@ -13,7 +13,7 @@
 {
 	libusb_device *dev;
 	libusb_device_handle *devh;
-	volatile int transferred;
+	unsigned int transferred;
 	uint8_t data[STR_SIZE] = {
 		'I', ' ', 'S', 'e', 'e', ' ', 'd', 'e', 'a', 'd',
 		' ', 'p', 'o', 'n', 'e', 'y', ' ', 'i', 'n', ' ',
@@ -29,10 +29,9 @@
 	transferred = 0;
 	if ((devh = libusb_open_device_with_vid_pid(ctx, VID_TEST, PID_TEST)) != NULL) {
 		libusb_detach_kernel_driver(devh, 1);
-		dev = libusb_get_device(devh)
-		libusb_bulk_transfer(devh, /*endpoint*/, &data, STR_SIZE,
+		dev = libusb_get_device(devh);
+		libusb_bulk_transfer(devh, 0x83, data, STR_SIZE,
 		&transferred, 10000);
-		while (transferred != 1);
 		printf("transfer done.\n");
 	} else {
 		fprintf(stderr, "\nNo device match or lack of permissions.\n");

==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#43 (text+ko) ====

@@ -807,11 +807,6 @@
 	bxfer = (struct usb_transfer *) ((uint8_t *)xfer - 
 	    sizeof(struct usb_transfer));
 
-	if (xfer->buffer)
-		free(xfer->buffer);
-	if (xfer->user_data)
-		free(xfer->user_data);
-
 	free(bxfer);
 	dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_transfer leave");
 	return;
@@ -821,24 +816,24 @@
 libusb10_proxy(struct libusb20_transfer *xfer)
 {
 	struct usb_transfer *usb_backend;
+	struct libusb20_device *pdev;
 	libusb_transfer *usb_xfer;
 	libusb_context *ctx;
 	uint8_t status;
 	uint32_t iso_packets;
 	int i;
 
-	usb_backend = (struct usb_transfer *) ((uint8_t *)xfer - 
-	    sizeof(struct usb_transfer));
-
-	pthread_mutex_lock(&libusb20_lock);
-
 	status = libusb20_tr_get_status(xfer);
 	usb_xfer = libusb20_tr_get_priv_sc0(xfer);
+	usb_backend = (struct usb_transfer *) ((uint8_t *)usb_xfer - 
+	    sizeof(struct usb_transfer));
+	pdev = usb_xfer->dev_handle->dev->os_priv;
 	ctx = usb_xfer->dev_handle->dev->ctx;
 	GET_CONTEXT(ctx);
 
 	switch (status) {
 	case LIBUSB20_TRANSFER_COMPLETED:
+		printf("completed\n");
 		dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "LIBUSB20 SUBMIT");
 		usb_xfer->actual_length += libusb20_tr_get_actual_length(xfer);
 		usb_xfer->callback(usb_xfer);
@@ -848,6 +843,7 @@
 		pthread_mutex_unlock(&ctx->flying_transfers_lock);
 		break ;
 	case LIBUSB20_TRANSFER_START:
+		printf("start\n");
 		dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "LIBUSB20 START");
 		usb_xfer->actual_length = 0;
 		switch (usb_xfer->type) {
@@ -884,12 +880,14 @@
 		dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "LIBUSB20 SUBMITED");
 		break ;
 	default:
+		printf("default 0x%x\n", status);
 		usb_xfer->actual_length = 0;
 		usb_xfer->status = LIBUSB_TRANSFER_CANCELLED;
 
 		pthread_mutex_lock(&ctx->flying_transfers_lock);
 		LIST_DEL(&usb_backend->list);
 		pthread_mutex_unlock(&ctx->flying_transfers_lock);
+		usb_xfer->callback(usb_xfer);
 
 		break ;
 	}
@@ -923,11 +921,7 @@
 		dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "ERROR");
 		usb_xfer->status = LIBUSB_TRANSFER_ERROR;
 		break ;
-	default:
-		printf("other status : %i\n", status);
 	}
-
-	pthread_mutex_unlock(&libusb20_lock);
 }
 
 static int
@@ -996,7 +990,7 @@
 			case LIBUSB20_SPEED_FULL:
 				ret = 4096;
 				break ;
-			case LIBUSB20_SPEED_HIGH:
+			default:
 				ret = 16384;
 				break ;
 		}
@@ -1092,7 +1086,6 @@
 
 	buffsize = libusb_get_buffsize(pdev, xfer);
 	maxframe = libusb_get_maxframe(pdev, xfer);
-	printf("buffsize : 0x%.8x maxframe : 0x%.8x\n", buffsize, maxframe);
 	
 	ret = libusb20_tr_open(usb20_xfer[0], buffsize, 
 	    maxframe, xfer->endpoint);
@@ -1139,7 +1132,6 @@
 
 	pthread_mutex_lock(&libusb20_lock);
 	libusb20_tr_stop(xfer->os_priv);
-	libusb20_tr_close(xfer->os_priv);
 	pthread_mutex_unlock(&libusb20_lock);
 
 	dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer leave");

==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#16 (text+ko) ====

@@ -121,6 +121,9 @@
 	int timeout;
 	int i;
        
+	GET_CONTEXT(ctx);
+	dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "handle_events enter");
+
 	nfds = 0;
 	i = -1;
 
@@ -150,10 +153,10 @@
 	ret = poll(fds, nfds, timeout);
 	if (ret == 0) {
 		free(fds);
-		return(handle_timeouts(ctx));
+		return (handle_timeouts(ctx));
 	} else if (ret == -1 && errno == EINTR) {
 		free(fds);
-		return LIBUSB_ERROR_INTERRUPTED;
+		return (LIBUSB_ERROR_INTERRUPTED);
 	} else if (ret < 0) {
 		free(fds);
 		return (LIBUSB_ERROR_IO);
@@ -171,8 +174,8 @@
 
 	pthread_mutex_lock(&ctx->open_devs_lock);
 	for (i = 0 ; i < nfds && ret > 0 ; i++) {
+
 		tfds = &fds[i];
-
 		if (!tfds->revents)
 			continue;
 
@@ -188,21 +191,26 @@
 			continue ;
 		}
 
+
 		pthread_mutex_lock(&libusb20_lock);
 		dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "LIBUSB20_PROCESS");
 		ret = libusb20_dev_process(devh->os_priv);
 		pthread_mutex_unlock(&libusb20_lock);
 
+
 		if (ret == 0 || ret == LIBUSB20_ERROR_NO_DEVICE)
 		       	continue;
 		else if (ret < 0)
 			goto out;
 	}
+
+	ret = 0;
 out:
 	pthread_mutex_unlock(&ctx->open_devs_lock);
 
 handled:
 	free(fds);
+	dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "handle_events leave");
 	return ret;
 }
 
@@ -538,6 +546,7 @@
 	int *complet;
        
 	ctx = NULL;
+	GET_CONTEXT(ctx);
 	dprintf(ctx, LIBUSB_DEBUG_TRANSFER, "CALLBACK ENTER");
 
 	complet = transfer->user_data;
@@ -556,7 +565,7 @@
 	int complet;
 	int ret;
 
-	ctx = NULL;
+	ctx = devh->dev->ctx;
 	GET_CONTEXT(ctx);
 	dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_control_transfer enter");
 
@@ -598,16 +607,18 @@
 		return (ret);
 	}
 
-	while (!complet)
-		if ((ret = libusb_handle_events(devh->dev->ctx)) < 0) {
+	while (complet == 0)
+		if ((ret = libusb_handle_events(ctx)) < 0) {
 			libusb_cancel_transfer(xfer);
+			while (complet == 0)
+				if (libusb_handle_events(ctx) < 0) {
+					break;
+				}
 			libusb_free_transfer(xfer);
-			while (!complet)
-				if (libusb_handle_events(devh->dev->ctx))
-					break;
 			return (ret);
 		}
 
+
 	if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
 		memcpy(data, buff + sizeof(libusb_control_setup), wLength);
 
@@ -668,7 +679,7 @@
 			libusb_cancel_transfer(xfer);
 			libusb_free_transfer(xfer);
 			while (complet == 0) {
-				if (libusb_handle_events(ctx))
+				if (libusb_handle_events(ctx) < 0)
 					break ;
 			}
 			return (ret);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906221909.n5MJ9DnW052270>