PERFORCE change 165853 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Thu Jul 9 08:16:48 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165853
Change 165853 by hselasky at hselasky_laptop001 on 2009/07/09 08:16:15
LibUSB:
- make GET_CONTEXT macro more obvious
- fix compile warnings and a bug in libusb_get_config_descriptor()
Affected files ...
.. //depot/projects/usb/src/lib/libusb/libusb.h#6 edit
.. //depot/projects/usb/src/lib/libusb/libusb10.c#6 edit
.. //depot/projects/usb/src/lib/libusb/libusb10.h#3 edit
.. //depot/projects/usb/src/lib/libusb/libusb10_desc.c#5 edit
.. //depot/projects/usb/src/lib/libusb/libusb10_io.c#4 edit
Differences ...
==== //depot/projects/usb/src/lib/libusb/libusb.h#6 (text+ko) ====
@@ -392,6 +392,7 @@
int libusb_set_configuration(libusb_device_handle * devh, int configuration);
int libusb_claim_interface(libusb_device_handle * devh, int interface_number);
int libusb_release_interface(libusb_device_handle * devh, int interface_number);
+int libusb_reset_device(libusb_device_handle * dev);
int libusb_kernel_driver_active(libusb_device_handle * devh, int interface);
int libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
int libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
==== //depot/projects/usb/src/lib/libusb/libusb10.c#6 (text+ko) ====
@@ -47,7 +47,7 @@
void
libusb_set_debug(libusb_context * ctx, int level)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
if (ctx)
ctx->debug = level;
}
@@ -120,7 +120,7 @@
void
libusb_exit(libusb_context * ctx)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_exit enter");
usb_remove_pollfd(ctx, ctx->ctrl_pipe[0]);
@@ -148,7 +148,7 @@
struct libusb20_backend *usb_backend;
int i;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_list enter");
usb_backend = libusb20_be_alloc_default();
@@ -220,8 +220,7 @@
int i;
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_device_list enter");
if (list == NULL)
@@ -240,8 +239,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_bus_number enter");
if (dev == NULL)
@@ -255,8 +253,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_address enter");
if (dev == NULL)
@@ -275,8 +272,7 @@
libusb_context *ctx;
int i, j, k, ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_max_packet_size enter");
if (dev == NULL)
@@ -311,8 +307,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_ref_device enter");
if (dev == NULL)
@@ -331,8 +326,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_unref_device enter");
if (dev == NULL)
@@ -362,7 +356,7 @@
unsigned char dummy;
int err;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open enter");
dummy = 1;
@@ -432,7 +426,7 @@
struct LIBUSB20_DEVICE_DESC_DECODED *pdesc;
int i, j;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open_device_width_vid_pid enter");
devh = NULL;
@@ -471,7 +465,7 @@
ctx = devh->dev->ctx;
pdev = devh->os_priv;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close enter");
pthread_mutex_lock(&ctx->pollfd_modify_lock);
@@ -538,8 +532,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device enter");
if (devh == NULL)
@@ -554,8 +547,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_configuration enter");
if (devh == NULL || config == NULL)
@@ -574,8 +566,7 @@
struct libusb20_device *pdev;
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_configuration enter");
if (devh == NULL)
@@ -594,8 +585,7 @@
libusb_context *ctx;
int ret = 0;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_claim_interface enter");
if (dev == NULL)
@@ -622,8 +612,7 @@
libusb_context *ctx;
int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_release_interface enter");
ret = 0;
@@ -650,10 +639,8 @@
int interface_number, int alternate_setting)
{
libusb_context *ctx;
- int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_interface_alt_setting enter");
if (dev == NULL)
@@ -685,8 +672,7 @@
libusb_context *ctx;
int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_clear_halt enter");
pdev = devh->os_priv;
@@ -716,8 +702,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_reset_device enter");
if (dev == NULL)
@@ -733,8 +718,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_kernel_driver_active enter");
if (devh == NULL)
@@ -750,8 +734,7 @@
struct libusb20_device *pdev;
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_detach_kernel_driver enter");
if (devh == NULL)
@@ -774,8 +757,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_attach_kernel_driver enter");
if (devh == NULL)
@@ -795,8 +777,7 @@
libusb_context *ctx;
int len;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_alloc_transfer enter");
len = sizeof(struct libusb_transfer) +
@@ -823,8 +804,7 @@
struct usb_transfer *bxfer;
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_transfer enter");
if (xfer == NULL)
@@ -933,7 +913,7 @@
sizeof(struct usb_transfer));
pdev = usb_xfer->dev_handle->dev->os_priv;
ctx = usb_xfer->dev_handle->dev->ctx;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
switch (status) {
case LIBUSB20_TRANSFER_COMPLETED:
@@ -1042,10 +1022,8 @@
libusb_context *ctx;
int maxframe;
int buffsize;
- int num_frame;
int ep_idx;
int ret;
- int i;
if (xfer == NULL)
return (LIBUSB_ERROR_NO_MEM);
@@ -1167,8 +1145,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter");
if (xfer == NULL)
==== //depot/projects/usb/src/lib/libusb/libusb10.h#3 (text+ko) ====
@@ -26,22 +26,10 @@
#ifndef __LIBUSB10_H__
#define __LIBUSB10_H__
-/*
- * The two following macros were taken from the original LibUSB v1.0
- * for sake of compatibility:
- */
-
-static int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out);
-static int handle_timeouts(struct libusb_context *ctx);
-static int handle_events(struct libusb_context *ctx, struct timeval *tv);
extern struct libusb_context *usbi_default_context;
extern pthread_mutex_t libusb20_lock;
-/* if ctx is NULL use default context*/
-
-#define GET_CONTEXT(ctx) \
- if (ctx == NULL) ctx = usbi_default_context;
-
+#define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define USB_TIMED_OUT (1<<0)
#define UNEXPORTED __attribute__((__visibility__("hidden")))
==== //depot/projects/usb/src/lib/libusb/libusb10_desc.c#5 (text+ko) ====
@@ -44,8 +44,7 @@
struct libusb20_device *pdev;
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor enter");
if ((dev == NULL) || (desc == NULL))
@@ -81,8 +80,7 @@
libusb_context *ctx;
uint8_t idx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor enter");
pdev = dev->os_priv;
@@ -110,8 +108,7 @@
uint8_t nif, nend, nalt, i, j, k;
uint32_t if_idx, endp_idx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor enter");
if (dev == NULL || config == NULL)
@@ -147,7 +144,7 @@
(*config)->interface = (libusb_interface *)(*config +
sizeof(libusb_config_descriptor));
- for (i = if_idx = endp_idx = 0 ; i < nif ; if_idx, i++) {
+ for (i = if_idx = endp_idx = 0 ; i < nif ; if_idx++, i++) {
(*config)->interface[i].altsetting = (libusb_interface_descriptor *)
(*config + sizeof(libusb_config_descriptor) +
(nif * sizeof(libusb_interface)) +
@@ -238,8 +235,7 @@
libusb_context *ctx;
int i;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value enter");
if (dev == NULL || config == NULL)
@@ -267,8 +263,7 @@
{
libusb_context *ctx;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor enter");
free(config);
@@ -281,10 +276,8 @@
{
struct libusb20_device *pdev;
libusb_context *ctx;
- int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii enter");
if (dev == NULL || data == NULL)
==== //depot/projects/usb/src/lib/libusb/libusb10_io.c#4 (text+ko) ====
@@ -38,6 +38,10 @@
#include "libusb.h"
#include "libusb10.h"
+static int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out);
+static int handle_timeouts(struct libusb_context *ctx);
+static int handle_events(struct libusb_context *ctx, struct timeval *tv);
+
UNEXPORTED int
usb_add_pollfd(libusb_context *ctx, int fd, short events)
{
@@ -161,7 +165,7 @@
return ;
}
-UNEXPORTED int
+static int
get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out)
{
struct timeval timeout;
@@ -183,7 +187,7 @@
return (0);
}
-UNEXPORTED int
+static int
handle_timeouts(struct libusb_context *ctx)
{
struct timespec sys_ts;
@@ -193,7 +197,7 @@
struct libusb_transfer *uxfer;
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
ret = 0;
pthread_mutex_lock(&ctx->flying_transfers_lock);
@@ -226,25 +230,21 @@
return (ret);
}
-UNEXPORTED int
+static int
handle_events(struct libusb_context *ctx, struct timeval *tv)
{
struct libusb_pollfd *tmppollfd;
struct libusb_device_handle *devh;
struct usb_pollfd *ipollfd;
- struct usb_transfer *cur;
- struct usb_transfer *cancel;
- struct libusb_transfer *xfer;
struct pollfd *fds;
struct pollfd *tfds;
nfds_t nfds;
int tmpfd;
- int tmp;
int ret;
int timeout;
int i;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "handle_events enter");
nfds = 0;
@@ -339,7 +339,7 @@
{
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_try_lock_events enter");
pthread_mutex_lock(&ctx->pollfd_modify_lock);
@@ -363,7 +363,7 @@
void
libusb_lock_events(libusb_context * ctx)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_lock_events enter");
pthread_mutex_lock(&ctx->events_lock);
@@ -375,7 +375,7 @@
void
libusb_unlock_events(libusb_context * ctx)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_unlock_events enter");
ctx->event_handler_active = 0;
@@ -393,7 +393,7 @@
{
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_event_handling_ok enter");
pthread_mutex_lock(&ctx->pollfd_modify_lock);
@@ -412,7 +412,7 @@
{
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_event_handler_active enter");
pthread_mutex_lock(&ctx->pollfd_modify_lock);
@@ -429,7 +429,7 @@
void
libusb_lock_event_waiters(libusb_context * ctx)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_lock_event_waiters enter");
pthread_mutex_lock(&ctx->event_waiters_lock);
@@ -440,7 +440,7 @@
void
libusb_unlock_event_waiters(libusb_context * ctx)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_unlock_event_waiters enter");
pthread_mutex_unlock(&ctx->event_waiters_lock);
@@ -454,7 +454,7 @@
int ret;
struct timespec ts;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_wait_for_event enter");
if (tv == NULL) {
@@ -487,11 +487,10 @@
int
libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv)
{
- struct timeval timeout;
struct timeval poll_timeout;
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_timeout enter");
ret = get_next_timeout(ctx, tv, &poll_timeout);
@@ -529,7 +528,7 @@
struct timeval tv;
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events enter");
tv.tv_sec = 2;
@@ -546,7 +545,7 @@
int ret;
struct timeval poll_tv;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_locked enter");
ret = get_next_timeout(ctx, tv, &poll_tv);
@@ -570,7 +569,7 @@
int found;
int ret;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_next_timeout enter");
found = 0;
@@ -610,7 +609,7 @@
libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
void *user_data)
{
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_pollfd_notifiers enter");
ctx->fd_added_cb = added_cb;
@@ -627,7 +626,7 @@
libusb_pollfd **ret;
int i;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_pollfds enter");
i = 0;
@@ -695,8 +694,7 @@
libusb_context *ctx;
int *pdone;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done");
@@ -729,7 +727,7 @@
return (LIBUSB_ERROR_NO_MEM);
ctx = devh->dev->ctx;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(ctx);
xfer->dev_handle = devh;
xfer->endpoint = endpoint;
@@ -797,8 +795,7 @@
libusb_context *ctx;
int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_bulk_transfer enter");
ret = do_transfer(devh, endpoint, data, length, transferred,
@@ -819,8 +816,7 @@
libusb_context *ctx;
int ret;
- ctx = NULL;
- GET_CONTEXT(ctx);
+ ctx = GET_CONTEXT(NULL);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer enter");
ret = do_transfer(devh, endpoint, data, length, transferred,
More information about the p4-projects
mailing list