diff options
author | Namyoon Woo <namyoon@chromium.org> | 2019-02-26 16:21:37 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-14 21:41:55 -0700 |
commit | c91a91b0f4fc5e171a766a1c55692504dbcf278e (patch) | |
tree | ab03e2bc6224a7dd587be82fc4aef352313a6045 /util | |
parent | f8a8113a014b76590cb789013dcc541b74199f2d (diff) | |
download | chrome-ec-c91a91b0f4fc5e171a766a1c55692504dbcf278e.tar.gz |
util/usb_if: return failure when usb device cannot be claimed.
This CL returns an error code when usb device finding fails.
BUG=none
BRANCH=none
TEST=manually ran flash_ec on dragonegg in CCD with servod.
[Before this CL]
...
iteflash -W 0 -c ccd -e -w ${IMG}
found interface 5 endpoint 6, chunk_len 64
util/usb_if.c:106, libusb_claim_interface returned -6 (Resource busy)
READY <----- should not proceed.
-------
Using CCD device
util/usb_if.c:127, libusb_bulk_transfer returned -99 (Other error)
...
[After this CL]
...
iteflash -W 0 -c ccd -e -w ${IMG}
found interface 5 endpoint 6, chunk_len 64
util/usb_if.c:106, libusb_claim_interface returned -6 (Resource busy)
connect_to_ccd_i2c_bridge: usb_findit returned error -1
dut-control --port=9999 ccd_ec_boot_mode_uut:off
dut-control --port=9999 ccd_ec_boot_mode_bitbang:off
...
Change-Id: Ibec9828487b2fed5f5a5bc2012b8b9f29d182531
Signed-off-by: Namyoon Woo <namyoon@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1490831
Reviewed-by: Matthew Blecker <matthewb@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/usb_if.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/util/usb_if.c b/util/usb_if.c index 744faf2b16..1f0adfecda 100644 --- a/util/usb_if.c +++ b/util/usb_if.c @@ -76,7 +76,7 @@ int usb_findit(uint16_t vid, uint16_t pid, uint16_t subclass, r = libusb_init(NULL); if (r < 0) { USB_ERROR("libusb_init", r); - return -1; + goto terminate_usb_findit; } printf("open_device %04x:%04x\n", vid, pid); @@ -84,17 +84,17 @@ int usb_findit(uint16_t vid, uint16_t pid, uint16_t subclass, uep->devh = libusb_open_device_with_vid_pid(NULL, vid, pid); if (!uep->devh) { fprintf(stderr, "Can't find device\n"); - return -1; + goto terminate_usb_findit; } iface_num = find_interface(subclass, protocol, uep); if (iface_num < 0) { - fprintf(stderr, "USB FW update not supported by that device\n"); - usb_shut_down(uep); + fprintf(stderr, "USB interface %d is not found\n", uep->ep_num); + goto terminate_usb_findit; } if (!uep->chunk_len) { fprintf(stderr, "wMaxPacketSize isn't valid\n"); - usb_shut_down(uep); + goto terminate_usb_findit; } printf("found interface %d endpoint %d, chunk_len %d\n", @@ -104,11 +104,16 @@ int usb_findit(uint16_t vid, uint16_t pid, uint16_t subclass, r = libusb_claim_interface(uep->devh, iface_num); if (r < 0) { USB_ERROR("libusb_claim_interface", r); - usb_shut_down(uep); + goto terminate_usb_findit; } printf("READY\n-------\n"); return 0; + +terminate_usb_findit: + if (uep->devh) + usb_shut_down(uep); + return -1; } int usb_trx(struct usb_endpoint *uep, void *outbuf, int outlen, |