don't let init fail if usb_set_configuration() fails; be more verbose in USB init

This commit is contained in:
marschap
2008-09-22 19:24:12 +00:00
parent 58499eab8d
commit 48cbc7d2d9
2 changed files with 27 additions and 7 deletions
+12 -5
View File
@@ -376,23 +376,30 @@ PrivateData *p;
if (p->udh != NULL) {
debug(RPT_DEBUG, "%s: opening device succeeded", drvthis->name);
errno = 0;
if (usb_set_configuration(p->udh, 1) < 0) {
usb_close(p->udh);
report(RPT_ERR, "%s: unable to set configuration", drvthis->name);
return -1;
report(RPT_WARNING, "%s: unable to set configuration: %s",
drvthis->name, strerror(errno));
}
errno = 0;
if (usb_claim_interface(p->udh, 1) < 0) {
#if defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
report(RPT_WARNING, "%s: interface may be claimed by kernel driver, attempting to detach it",
drvthis->name);
errno = 0;
if ((usb_detach_kernel_driver_np(p->udh, 1) < 0) ||
(usb_claim_interface(p->udh, 1) < 0)) {
report(RPT_ERR, "%s: unable to re-claim interface: %s",
drvthis->name, strerror(errno));
usb_close(p->udh);
report(RPT_ERR, "%s: unable to re-claim interface", drvthis->name);
return -1;
}
#else
report(RPT_ERR, "%s: unable to claim interface: %s",
drvthis->name, strerror(errno));
usb_close(p->udh);
report(RPT_ERR, "%s: unable to claim interface", drvthis->name);
return -1;
#endif
}
+15 -2
View File
@@ -148,17 +148,30 @@ hd_init_bwct_usb(Driver *drvthis)
if (p->usbHandle != NULL) {
debug(RPT_DEBUG, "hd_init_bwct_usb: opening device succeeded");
errno = 0;
if (usb_set_configuration(p->usbHandle, p->usbIndex) < 0) {
report(RPT_WARNING, "hd_init_bwct_usb: unable to set configuration: %s",
strerror(errno));
}
errno = 0;
if (usb_claim_interface(p->usbHandle, p->usbIndex) < 0) {
#if defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
report(RPT_WARNING, "hd_init_bwct_usb: interface may be claimed by "
"kernel driver, attempting to detach it");
errno = 0;
if ((usb_detach_kernel_driver_np(p->usbHandle, p->usbIndex) < 0) ||
(usb_claim_interface(p->usbHandle, p->usbIndex) < 0)) {
report(RPT_ERR, "hd_init_bwct_usb: unable to re-claim interface: %s",
strerror(errno));
usb_close(p->usbHandle);
report(RPT_ERR, "hd_init_bwct_usb: unable to re-claim interface");
return -1;
}
#else
report(RPT_ERR, "hd_init_bwct_usb: unable to claim interface: %s",
strerror(errno));
usb_close(p->usbHandle);
report(RPT_ERR, "hd_init_bwct_usb: unable to claim interface");
return -1;
#endif
}