X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsaleae-logic16%2Fapi.c;h=cfddfbb082d0fb990596f6af627f4eb768e60ae3;hb=7e463623382e1f574fde150b3fc88a65eaebb578;hp=f7430c212aec28e036a105f0f7a3783f41b6f88f;hpb=d2f7c417fdd96a13d8fd86350d2fc13db16f626c;p=libsigrok.git diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index f7430c21..cfddfbb0 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -235,17 +235,13 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; struct libusb_device_descriptor des; struct drv_context *drvc; - int ret, i, device_count; + int ret = SR_ERR, i, device_count; char connection_id[64]; di = sdi->driver; drvc = di->context; usb = sdi->conn; - if (sdi->status == SR_ST_ACTIVE) - /* Device is already in use. */ - return SR_ERR; - device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); if (device_count < 0) { sr_err("Failed to get device list: %s.", @@ -280,6 +276,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) } else { sr_err("Failed to open device: %s.", libusb_error_name(ret)); + ret = SR_ERR; break; } @@ -287,13 +284,16 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) if (ret == LIBUSB_ERROR_BUSY) { sr_err("Unable to claim USB interface. Another " "program or driver has already claimed it."); + ret = SR_ERR; break; } else if (ret == LIBUSB_ERROR_NO_DEVICE) { sr_err("Device has been disconnected."); + ret = SR_ERR; break; } else if (ret != 0) { sr_err("Unable to claim interface: %s.", libusb_error_name(ret)); + ret = SR_ERR; break; } @@ -302,15 +302,17 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) break; } - sdi->status = SR_ST_ACTIVE; sr_info("Opened device on %d.%d (logical) / %s (physical), interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); + ret = SR_OK; + break; } + libusb_free_device_list(devlist, 1); - if (sdi->status != SR_ST_ACTIVE) { + if (ret != SR_OK) { if (usb->devhdl) { libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); @@ -460,9 +462,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; ret = SR_OK; @@ -674,9 +673,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned char *buf; size_t size, convsize; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn;