Inconsistent handling of libusb_reset_device return value
Multiplatform USB DFU host utility
Brought to you by:
tormod
dfu-util -D file -R returns -5 (LIBUSB_ERROR_NOT_FOUND) after successfully programming and resetting my homegrown device.
That -5 comes from libusb_reset_device, and I can see that this particular return value from is specifically ignored in the error reporting following the call, but is nevertheless allowed to bubble up, all the way to the return from main.
Example at src/dfu_load.c:203:
case DFU_STATE_dfuMANIFEST_WAIT_RST:
printf("Resetting USB to switch back to runtime mode\n");
ret = libusb_reset_device(dif->dev_handle);
if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND) {
fprintf(stderr, "error resetting after download (%s)\n",
libusb_error_name(ret));
}
break;
A proposed patch is attached.
Anonymous
Thanks! This seems to make sense.
I have committed a patch received earlier, in commit 4800abb, and which I believe does the same as your third chunk. Your second chunk seems not needed, because
retwill be reset later in any case, it can be considered a "local" variable here.Your first chunk seems to make sense, but actually a proper DFU device will never report to be in dfuMANIFEST-WAIT-RESET state, please see section 8 of DFU 1.1. So maybe you should review your homegrown device.
This is also related to the discussion in https://sourceforge.net/p/dfu-util/dfu-util/merge-requests/17/
I now committed the equivalent of your first chunk in commit 83b4abc.