mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-04-11 00:56:18 +00:00
acr122_usb: Check usb_open result
This commit is contained in:
committed by
Philippe Teuwen
parent
9cb9e0e6da
commit
27c2c801e8
@@ -327,11 +327,12 @@ acr122_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
|||||||
}
|
}
|
||||||
|
|
||||||
usb_dev_handle *udev = usb_open(dev);
|
usb_dev_handle *udev = usb_open(dev);
|
||||||
|
if (!udev)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Set configuration
|
// Set configuration
|
||||||
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
|
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name);
|
||||||
usb_close(udev);
|
|
||||||
snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
||||||
device_found++;
|
device_found++;
|
||||||
// Test if we reach the maximum "wanted" devices
|
// Test if we reach the maximum "wanted" devices
|
||||||
@@ -414,6 +415,10 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
|||||||
}
|
}
|
||||||
// Open the USB device
|
// Open the USB device
|
||||||
data.pudh = usb_open(dev);
|
data.pudh = usb_open(dev);
|
||||||
|
|
||||||
|
if (data.pudh == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Reset device
|
// Reset device
|
||||||
usb_reset(data.pudh);
|
usb_reset(data.pudh);
|
||||||
// Retrieve end points
|
// Retrieve end points
|
||||||
@@ -422,6 +427,7 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
|||||||
int res = usb_claim_interface(data.pudh, 0);
|
int res = usb_claim_interface(data.pudh, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror(res));
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror(res));
|
||||||
|
if (data.pudh)
|
||||||
usb_close(data.pudh);
|
usb_close(data.pudh);
|
||||||
// we failed to use the specified device
|
// we failed to use the specified device
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
@@ -430,6 +436,7 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
|||||||
res = usb_set_altinterface(data.pudh, 0);
|
res = usb_set_altinterface(data.pudh, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror(res));
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror(res));
|
||||||
|
if (data.pudh)
|
||||||
usb_close(data.pudh);
|
usb_close(data.pudh);
|
||||||
// we failed to use the specified device
|
// we failed to use the specified device
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
@@ -474,6 +481,7 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
|||||||
pnd->driver = &acr122_usb_driver;
|
pnd->driver = &acr122_usb_driver;
|
||||||
|
|
||||||
if (acr122_usb_init(pnd) < 0) {
|
if (acr122_usb_init(pnd) < 0) {
|
||||||
|
if (data.pudh)
|
||||||
usb_close(data.pudh);
|
usb_close(data.pudh);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user