mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-03 21:18:59 +00:00
MFC r338679:
Improve LibUSB debugging by simultaneously allowing both function and transfer prints. Make sure the debug level comes from the correct USB context. Found by: Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com> PR: 231264 Sponsored by: Mellanox Technologies
This commit is contained in:
parent
fa813063bd
commit
e46a165203
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=338792
@ -39,22 +39,24 @@
|
||||
#define HOTPLUG_LOCK(ctx) pthread_mutex_lock(&(ctx)->hotplug_lock)
|
||||
#define HOTPLUG_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->hotplug_lock)
|
||||
|
||||
#define DPRINTF(ctx, dbg, format, args...) do { \
|
||||
if ((ctx)->debug == dbg) { \
|
||||
switch (dbg) { \
|
||||
case LIBUSB_DEBUG_FUNCTION: \
|
||||
printf("LIBUSB_FUNCTION: " \
|
||||
format "\n", ## args); \
|
||||
break; \
|
||||
case LIBUSB_DEBUG_TRANSFER: \
|
||||
printf("LIBUSB_TRANSFER: " \
|
||||
format "\n", ## args); \
|
||||
break; \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
#define DPRINTF(ctx, dbg, format, ...) do { \
|
||||
switch (dbg) { \
|
||||
case LIBUSB_DEBUG_FUNCTION: \
|
||||
if ((ctx)->debug & LIBUSB_DEBUG_FUNCTION) { \
|
||||
printf("LIBUSB_FUNCTION: " \
|
||||
format "\n", ## __VA_ARGS__); \
|
||||
} \
|
||||
break; \
|
||||
case LIBUSB_DEBUG_TRANSFER: \
|
||||
if ((ctx)->debug & LIBUSB_DEBUG_TRANSFER) { \
|
||||
printf("LIBUSB_TRANSFER: " \
|
||||
format "\n", ## __VA_ARGS__); \
|
||||
} \
|
||||
break; \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* internal structures */
|
||||
|
||||
|
@ -487,13 +487,26 @@ libusb_control_transfer(libusb_device_handle *devh,
|
||||
return (actlen);
|
||||
}
|
||||
|
||||
static libusb_context *
|
||||
libusb10_get_context_by_device_handle(libusb_device_handle *devh)
|
||||
{
|
||||
libusb_context *ctx;
|
||||
|
||||
if (devh != NULL)
|
||||
ctx = libusb_get_device(devh)->ctx;
|
||||
else
|
||||
ctx = NULL;
|
||||
|
||||
return (GET_CONTEXT(ctx));
|
||||
}
|
||||
|
||||
static void
|
||||
libusb10_do_transfer_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
libusb_context *ctx;
|
||||
int *pdone;
|
||||
|
||||
ctx = GET_CONTEXT(NULL);
|
||||
ctx = libusb10_get_context_by_device_handle(transfer->dev_handle);
|
||||
|
||||
DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "sync I/O done");
|
||||
|
||||
@ -583,7 +596,8 @@ libusb_bulk_transfer(libusb_device_handle *devh,
|
||||
libusb_context *ctx;
|
||||
int ret;
|
||||
|
||||
ctx = GET_CONTEXT(NULL);
|
||||
ctx = libusb10_get_context_by_device_handle(devh);
|
||||
|
||||
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_bulk_transfer enter");
|
||||
|
||||
ret = libusb10_do_transfer(devh, endpoint, data, length, transferred,
|
||||
@ -601,7 +615,8 @@ libusb_interrupt_transfer(libusb_device_handle *devh,
|
||||
libusb_context *ctx;
|
||||
int ret;
|
||||
|
||||
ctx = GET_CONTEXT(NULL);
|
||||
ctx = libusb10_get_context_by_device_handle(devh);
|
||||
|
||||
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer enter");
|
||||
|
||||
ret = libusb10_do_transfer(devh, endpoint, data, length, transferred,
|
||||
|
Loading…
Reference in New Issue
Block a user