From: Uwe Hermann Date: Fri, 7 Jul 2017 20:36:24 +0000 (+0200) Subject: sr_dev_open(): Set status to SR_ST_ACTIVE upon success. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7e463623382e1f574fde150b3fc88a65eaebb578;p=libsigrok.git sr_dev_open(): Set status to SR_ST_ACTIVE upon success. This ensures consistent checks and log messages across all drivers and reduces the per-driver boilerplate. --- diff --git a/src/device.c b/src/device.c index e5cbf4ef..14b56b2f 100644 --- a/src/device.c +++ b/src/device.c @@ -545,11 +545,19 @@ SR_API int sr_dev_clear(const struct sr_dev_driver *driver) } /** - * Open the specified device. + * Open the specified device instance. + * + * If the device instance is already open (sdi->status == SR_ST_ACTIVE), + * SR_ERR will be returned and no re-opening of the device will be attempted. + * + * If opening was successful, sdi->status is set to SR_ST_ACTIVE, otherwise + * it will be left unchanged. * * @param sdi Device instance to use. Must not be NULL. * - * @return SR_OK upon success, a negative error code upon errors. + * @retval SR_OK Success. + * @retval SR_ERR_ARG Invalid arguments. + * @retval SR_ERR Device instance was already active, or other error. * * @since 0.2.0 */ @@ -558,7 +566,7 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi) int ret; if (!sdi || !sdi->driver || !sdi->driver->dev_open) - return SR_ERR; + return SR_ERR_ARG; if (sdi->status == SR_ST_ACTIVE) { sr_err("%s: Device instance already active, can't re-open.", @@ -566,10 +574,13 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - sr_dbg("%s: Opening device.", sdi->driver->name) + sr_dbg("%s: Opening device instance.", sdi->driver->name); ret = sdi->driver->dev_open(sdi); + if (ret == SR_OK) + sdi->status = SR_ST_ACTIVE; + return ret; } diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 676be07f..50a1d489 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -140,18 +140,13 @@ static int dev_open(struct sr_dev_inst *sdi) devc = sdi->priv; - /* Make sure it's an ASIX SIGMA. */ if ((ret = ftdi_usb_open_desc(&devc->ftdic, - USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { - - sr_err("ftdi_usb_open failed: %s", - ftdi_get_error_string(&devc->ftdic)); - - return 0; + USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { + sr_err("Failed to open device (%d): %s.", + ret, ftdi_get_error_string(&devc->ftdic)); + return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index c00c3798..fff5e8da 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -130,8 +130,6 @@ static int dev_open(struct sr_dev_inst *sdi) { (void)sdi; - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 0d022f2b..d8329897 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -157,8 +157,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - /* We're good to go now */ - sdi->status = SR_ST_ACTIVE; return SR_OK; } diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index cafba7da..44424241 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -95,9 +95,7 @@ static int dev_open(struct sr_dev_inst *sdi) usb = sdi->conn; devc = sdi->priv; - if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK) - sdi->status = SR_ST_ACTIVE; - else + if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) < 0) return SR_ERR; /* Detach kernel drivers which grabbed this device (if any). */ @@ -122,7 +120,7 @@ static int dev_open(struct sr_dev_inst *sdi) } sr_dbg("Successfully claimed interface 0."); - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 9f793969..1bfc82e6 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -272,15 +272,12 @@ static int dev_open(struct sr_dev_inst *sdi) /* Wait 100ms. */ g_usleep(100 * 1000); - sdi->status = SR_ST_ACTIVE; - - if (ret == SR_OK) - return SR_OK; + return SR_OK; err_ftdi_free: ftdi_free(devc->ftdic); /* Close device (if open), free FTDI context. */ devc->ftdic = NULL; - return ret; + return SR_ERR; } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 236bb316..3f4ae41e 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -182,7 +182,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) static int dev_open(struct sr_dev_inst *sdi) { - sdi->status = SR_ST_ACTIVE; + (void)sdi; return SR_OK; } diff --git a/src/hardware/dreamsourcelab-dslogic/protocol.c b/src/hardware/dreamsourcelab-dslogic/protocol.c index 43280cc5..77d1e0ef 100644 --- a/src/hardware/dreamsourcelab-dslogic/protocol.c +++ b/src/hardware/dreamsourcelab-dslogic/protocol.c @@ -560,7 +560,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) struct dev_context *devc; struct drv_context *drvc; struct version_info vi; - int ret, i, device_count; + int ret = SR_ERR, i, device_count; uint8_t revid; char connection_id[64]; @@ -584,9 +584,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) if ((sdi->status == SR_ST_INITIALIZING) || (sdi->status == SR_ST_INACTIVE)) { - /* - * Check device by its physical USB bus/port address. - */ + /* Check device by its physical USB bus/port address. */ usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ @@ -603,6 +601,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) } else { sr_err("Failed to open device: %s.", libusb_error_name(ret)); + ret = SR_ERR; break; } @@ -611,7 +610,8 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) if ((ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE)) < 0) { sr_err("Failed to detach kernel driver: %s.", libusb_error_name(ret)); - return SR_ERR; + ret = SR_ERR; + break; } } } @@ -637,10 +637,10 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) sr_err("Expected firmware version %d.x, " "got %d.%d.", DSLOGIC_REQUIRED_VERSION_MAJOR, vi.major, vi.minor); + ret = SR_ERR; break; } - sdi->status = SR_ST_ACTIVE; sr_info("Opened device on %d.%d (logical) / %s (physical), " "interface %d, firmware %d.%d.", usb->bus, usb->address, connection_id, @@ -649,14 +649,14 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) sr_info("Detected REVID=%d, it's a Cypress CY7C68013%s.", revid, (revid != 1) ? " (FX2)" : "A (FX2LP)"); + ret = SR_OK; + break; } - libusb_free_device_list(devlist, 1); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + libusb_free_device_list(devlist, 1); - return SR_OK; + return ret; } SR_PRIV struct dev_context *dslogic_dev_new(void) diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 9aac98ae..3a3a8861 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -302,13 +302,14 @@ static int dev_open(struct sr_dev_inst *sdi) } sr_dbg("FTDI chip bitbang mode entered successfully."); - sdi->status = SR_ST_ACTIVE; - return SR_OK; + err_dev_open_close_ftdic: ftdi_usb_close(devc->ftdic); + err_ftdi_free: ftdi_free(devc->ftdic); + return SR_ERR; } diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index 422c84ea..e88bbd2f 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -147,7 +147,7 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) struct dev_context *devc; struct drv_context *drvc; struct version_info vi; - int ret, i, device_count; + int ret = SR_ERR, i, device_count; uint8_t revid; char connection_id[64]; @@ -190,6 +190,7 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) } else { sr_err("Failed to open device: %s.", libusb_error_name(ret)); + ret = SR_ERR; break; } @@ -198,7 +199,8 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) if ((ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE)) < 0) { sr_err("Failed to detach kernel driver: %s.", libusb_error_name(ret)); - return SR_ERR; + ret = SR_ERR; + break; } } } @@ -227,7 +229,6 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) break; } - sdi->status = SR_ST_ACTIVE; sr_info("Opened device on %d.%d (logical) / %s (physical), " "interface %d, firmware %d.%d.", usb->bus, usb->address, connection_id, @@ -236,14 +237,14 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) sr_info("Detected REVID=%d, it's a Cypress CY7C68013%s.", revid, (revid != 1) ? " (FX2)" : "A (FX2LP)"); + ret = SR_OK; + break; } - libusb_free_device_list(devlist, 1); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + libusb_free_device_list(devlist, 1); - return SR_OK; + return ret; } SR_PRIV struct dev_context *fx2lafw_dev_new(void) diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 2ab06957..30407c3f 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -98,8 +98,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 20b5779c..8e15a20d 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -137,8 +137,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (hmo_scope_state_get(sdi) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/hantek-6xxx/protocol.c b/src/hardware/hantek-6xxx/protocol.c index a08e126c..8e406ffe 100644 --- a/src/hardware/hantek-6xxx/protocol.c +++ b/src/hardware/hantek-6xxx/protocol.c @@ -27,7 +27,7 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; struct libusb_device_descriptor des; libusb_device **devlist; - int err, i; + int err = SR_ERR, i; char connection_id[64]; devc = sdi->priv; @@ -61,14 +61,16 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) usb->address = libusb_get_device_address(devlist[i]); } - 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); + + err = SR_OK; } else { sr_err("Failed to open device: %s.", libusb_error_name(err)); + err = SR_ERR; } /* If we made it here, we handled the device (somehow). */ @@ -77,10 +79,7 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) libusb_free_device_list(devlist, 1); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; - - return SR_OK; + return err; } SR_PRIV void hantek_6xxx_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 195b9804..19e42027 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -205,8 +205,6 @@ static int dev_open(struct sr_dev_inst *sdi) sr_scpi_send(scpi, "TRIG HOLD"); sr_scpi_get_float(scpi, "NPLC?", &devc->nplc); - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 9f752617..b6a1be5a 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -262,8 +262,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (!devc->samples) goto fail3; - sdi->status = SR_ST_ACTIVE; - return SR_OK; fail3: diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 66be858f..d13abf31 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -232,8 +232,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 1bc17b73..8d22fa0b 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -207,12 +207,11 @@ static int dev_open(struct sr_dev_inst *sdi) sr_dbg("Received ScanaPLUS device ID successfully: %02x %02x %02x.", devc->devid[0], devc->devid[1], devc->devid[2]); - sdi->status = SR_ST_ACTIVE; - return SR_OK; err_dev_open_close_ftdic: scanaplus_close(devc); + return SR_ERR; } diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 07d71f48..02c83e4c 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -171,9 +171,8 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 44d7643f..7c7eda9e 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -97,9 +97,8 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 075fff76..50094a40 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -141,8 +141,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (lecroy_xstream_state_get(sdi) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 241d5e0a..5924aeb9 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -180,8 +180,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - /* FIXME: discard serial buffer */ mso_check_trigger(devc->serial, &devc->trigger_state); sr_dbg("Trigger state: 0x%x.", devc->trigger_state); diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 970bfe95..451edeb2 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -203,8 +203,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (sr_modbus_open(modbus) < 0) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - maynuo_m97_set_bit(modbus, PC1, 1); return SR_OK; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 5995cdf8..8a0978b8 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -411,12 +411,7 @@ static int dev_open(struct sr_dev_inst *sdi) devc = sdi->priv; - if (p_ols_open(devc) != SR_OK) - return SR_ERR; - - sdi->status = SR_ST_ACTIVE; - - return SR_OK; + return p_ols_open(devc); } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 8276a9ed..aaff5115 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -133,6 +133,7 @@ SR_PRIV int p_ols_open(struct dev_context *devc) err_open_close_ftdic: ftdi_usb_close(devc->ftdic); + return SR_ERR; } diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 9fb2f406..1e35a541 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -445,8 +445,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 7d39cbdf..3ca5441a 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -162,12 +162,7 @@ static int dev_clear(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { - if (sr_scpi_open(sdi->conn) != SR_OK) - return SR_ERR; - - sdi->status = SR_ST_ACTIVE; - - return SR_OK; + return sr_scpi_open(sdi->conn); } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index a456d0b6..4dcd0aa9 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -205,8 +205,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (devc->dig_samplerate == 0) devc->dig_samplerate = samplerates[3]; - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 986b0257..cfddfbb0 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -235,7 +235,7 @@ 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; @@ -276,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; } @@ -283,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; } @@ -298,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); diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 50eabc9f..52b70d3e 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -255,8 +255,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (sr_scpi_open(scpi) < 0) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - devc = sdi->priv; scpi_cmd(sdi, devc->device->commands, SCPI_CMD_REMOTE); devc->beeper_was_set = FALSE; diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 59b36819..bb1e9e0b 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -303,8 +303,6 @@ static int dev_open(struct sr_dev_inst *sdi) /* This delay appears to be necessary for reliable operation. */ g_usleep(30 * 1000); - sdi->status = SR_ST_ACTIVE; - devc->active_fpga_config = FPGA_NOCONF; devc->short_transfer_quirk = FALSE; devc->state = STATE_IDLE; @@ -317,7 +315,6 @@ static int dev_open(struct sr_dev_inst *sdi) break; /* Rinse and repeat. */ - sdi->status = SR_ST_INACTIVE; sr_usb_close(usb); } diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index bc21f0f9..933b86ba 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -162,7 +162,6 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; return SR_OK; } diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index c6e0dd9a..15976707 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -98,16 +98,12 @@ static int dev_open(struct sr_dev_inst *sdi) struct sr_dev_driver *di; struct drv_context *drvc; struct sr_usb_dev_inst *usb; - int ret; di = sdi->driver; drvc = di->context; usb = sdi->conn; - if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK) - sdi->status = SR_ST_ACTIVE; - - return ret; + return sr_usb_open(drvc->sr_ctx->libusb_ctx, usb); } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index b340e40f..532d428e 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -127,9 +127,8 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 0b96a5d2..b8db2048 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -120,7 +120,6 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; return SR_OK; } diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 2faf7917..30b3ca05 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -147,8 +147,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (dlm_scope_state_query(sdi) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - return SR_OK; } diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 7803407a..20804ec9 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -264,8 +264,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (ret != SR_OK) return ret; - sdi->status = SR_ST_ACTIVE; - ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION); if (ret < 0) { sr_err("Unable to set USB configuration %d: %s.", diff --git a/src/std.c b/src/std.c index ccb73718..35da7088 100644 --- a/src/std.c +++ b/src/std.c @@ -152,23 +152,20 @@ SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi) * callback in drivers that use a serial port. The port is opened * with the SERIAL_RDWR flag. * - * If the open succeeded, the status field of the given sdi is set - * to SR_ST_ACTIVE. - * * @retval SR_OK Success. + * @retval SR_ERR_ARG Invalid arguments. * @retval SR_ERR Serial port open failed. */ SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi) { struct sr_serial_dev_inst *serial; - serial = sdi->conn; - if (serial_open(serial, SERIAL_RDWR) != SR_OK) - return SR_ERR; + if (!sdi || !sdi->conn) + return SR_ERR_ARG; - sdi->status = SR_ST_ACTIVE; + serial = sdi->conn; - return SR_OK; + return serial_open(serial, SERIAL_RDWR); } /**