From: Reto Schneider Date: Mon, 9 Jul 2012 22:12:54 +0000 (+0200) Subject: Produce more accurate error messages. X-Git-Url: https://git.ao2.it/libam7xxx.git/commitdiff_plain/38c3f5374d3c6305be89b18108fa0bf1de4f4cbd Produce more accurate error messages. --- diff --git a/src/am7xxx.c b/src/am7xxx.c index 5b98b84..d6615ba 100644 --- a/src/am7xxx.c +++ b/src/am7xxx.c @@ -310,7 +310,10 @@ static int read_data(am7xxx_device *dev, uint8_t *buffer, unsigned int len) int transferred = 0; ret = libusb_bulk_transfer(dev->usb_device, 0x81, buffer, len, &transferred, 0); - if (ret != 0 || (unsigned int)transferred != len) { + if (ret < 0) { + error(dev->ctx, "USB bulk transfer failed (%s)\n", libusb_error_name(ret)); + return ret; + } else if (ret != 0 || (unsigned int)transferred != len) { error(dev->ctx, "ret: %d\ttransferred: %d (expected %u)\n", ret, transferred, len); return ret; @@ -329,7 +332,10 @@ static int send_data(am7xxx_device *dev, uint8_t *buffer, unsigned int len) trace_dump_buffer(dev->ctx, "sending -->", buffer, len); ret = libusb_bulk_transfer(dev->usb_device, 0x1, buffer, len, &transferred, 0); - if (ret != 0 || (unsigned int)transferred != len) { + if (ret < 0) { + error(dev->ctx, "USB bulk transfer failed (%s)\n", libusb_error_name(ret)); + return ret; + } else if (ret != 0 || (unsigned int)transferred != len) { error(dev->ctx, "ret: %d\ttransferred: %d (expected %u)\n", ret, transferred, len); return ret; @@ -527,6 +533,7 @@ static int scan_devices(am7xxx_context *ctx, scan_op op, num_devices = libusb_get_device_list(ctx->usb_context, &list); if (num_devices < 0) { + error(ctx, "USB get device list failed (%s)\n", libusb_error_name(num_devices)); ret = -ENODEV; goto out; } @@ -537,8 +544,10 @@ static int scan_devices(am7xxx_context *ctx, scan_op op, unsigned int j; ret = libusb_get_device_descriptor(list[i], &desc); - if (ret < 0) + if (ret < 0) { + debug(ctx, "USB get device descriptor failed (%s)\n", libusb_error_name(ret)); continue; + } for (j = 0; j < ARRAY_SIZE(supported_devices); j++) { if (desc.idVendor == supported_devices[j].vendor_id @@ -578,7 +587,7 @@ static int scan_devices(am7xxx_context *ctx, scan_op op, ret = libusb_open(list[i], &((*dev)->usb_device)); if (ret < 0) { - debug(ctx, "libusb_open failed\n"); + debug(ctx, "libusb_open failed (%s)\n", libusb_error_name(ret)); goto out; } @@ -623,8 +632,10 @@ AM7XXX_PUBLIC int am7xxx_init(am7xxx_context **ctx) (*ctx)->log_level = AM7XXX_LOG_TRACE; ret = libusb_init(&((*ctx)->usb_context)); - if (ret < 0) + if (ret < 0) { + fatal("USB initialization failed (%s)\n", libusb_error_name(ret)); goto out_free_context; + } libusb_set_debug((*ctx)->usb_context, 3);