From: Uwe Hermann Date: Fri, 7 Jul 2017 18:42:04 +0000 (+0200) Subject: sr_dev_close(): Set status to SR_ST_INACTIVE. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;p=libsigrok.git sr_dev_close(): Set status to SR_ST_INACTIVE. 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 14b56b2f..9ba8bfc5 100644 --- a/src/device.c +++ b/src/device.c @@ -585,11 +585,21 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi) } /** - * Close the specified device. + * Close the specified device instance. + * + * If the device instance is not open (sdi->status != SR_ST_ACTIVE), + * SR_ERR_DEV_CLOSED will be returned and no closing will be attempted. + * + * Note: sdi->status will be set to SR_ST_INACTIVE, regardless of whether + * there are any errors during closing of the device instance (any errors + * will be reported via error code and log message, though). * * @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_DEV_CLOSED Device instance was not active. + * @retval SR_ERR Other error. * * @since 0.2.0 */ @@ -598,7 +608,7 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi) int ret; if (!sdi || !sdi->driver || !sdi->driver->dev_close) - return SR_ERR; + return SR_ERR_ARG; if (sdi->status != SR_ST_ACTIVE) { sr_err("%s: Device instance not active, can't close.", @@ -606,7 +616,9 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi) return SR_ERR_DEV_CLOSED; } - sr_dbg("%s: Closing device.", sdi->driver->name) + sdi->status = SR_ST_INACTIVE; + + sr_dbg("%s: Closing device instance.", sdi->driver->name); ret = sdi->driver->dev_close(sdi); diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 50a1d489..41a775a5 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -156,11 +156,7 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; - ftdi_usb_close(&devc->ftdic); - - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return (ftdi_usb_close(&devc->ftdic) == 0) ? SR_OK : SR_ERR; } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 6458ebf4..59252838 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -421,6 +421,7 @@ static int dev_close(struct sr_dev_inst *sdi) struct dev_context *devc; devc = sdi->priv; + if (devc->config_dirty) /* Some configuration changes were queued up but didn't * get sent to the device, likely because we were never diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index fff5e8da..c45ab77d 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -137,8 +137,6 @@ static int dev_close(struct sr_dev_inst *sdi) { (void)sdi; - sdi->status = SR_ST_INACTIVE; - return SR_OK; } diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index d8329897..ff8f0424 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -168,8 +168,6 @@ static int dev_close(struct sr_dev_inst *sdi) beaglelogic_munmap(devc); beaglelogic_close(devc); - sdi->status = SR_ST_INACTIVE; - return SR_OK; } diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 44424241..23b42e13 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -134,24 +134,18 @@ static int dev_close(struct sr_dev_inst *sdi) if ((ret = libusb_release_interface(usb->devhdl, 0))) sr_err("Failed to release interface 0: %s.\n", libusb_error_name(ret)); - else - sr_dbg("Successfully released interface 0.\n"); if (!ret && devc->detached_kernel_driver) { - if ((ret = libusb_attach_kernel_driver(usb->devhdl, 0))) { + if ((ret = libusb_attach_kernel_driver(usb->devhdl, 0))) sr_err("Failed to attach kernel driver: %s.\n", libusb_error_name(ret)); - } else { + else devc->detached_kernel_driver = 0; - sr_dbg("Successfully attached kernel driver.\n"); - } } libusb_close(usb->devhdl); - sdi->status = SR_ST_INACTIVE; - - return ret; + return (ret == 0) ? SR_OK : SR_ERR; } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 1bfc82e6..0c94b398 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -287,13 +287,14 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; - if (devc->ftdic && (ret = ftdi_usb_close(devc->ftdic)) < 0) + if (!devc->ftdic) + return SR_ERR_BUG; + + if ((ret = ftdi_usb_close(devc->ftdic)) < 0) sr_err("Failed to close FTDI device (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return (ret == 0) ? SR_OK : SR_ERR; } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 3f4ae41e..0dd0a38a 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -189,7 +189,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - sdi->status = SR_ST_INACTIVE; + (void)sdi; return SR_OK; } diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index e9e44502..d11861bb 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -382,14 +382,13 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 3a3a8861..5a7ac51e 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -319,13 +319,12 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; - if (devc->ftdic) { - ftdi_usb_close(devc->ftdic); - ftdi_free(devc->ftdic); - devc->ftdic = NULL; - } + if (!devc->ftdic) + return SR_ERR_BUG; - sdi->status = SR_ST_INACTIVE; + ftdi_usb_close(devc->ftdic); + ftdi_free(devc->ftdic); + devc->ftdic = NULL; return SR_OK; } diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 879fdf04..547f7229 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -438,14 +438,13 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 992cbd81..8bac10f1 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -334,12 +334,11 @@ static int dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc; - std_serial_dev_close(sdi); + devc = sdi->priv; - if ((devc = sdi->priv)) - devc->model = METRAHIT_NONE; + devc->model = METRAHIT_NONE; - return SR_OK; + return std_serial_dev_close(sdi); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 30407c3f..0b8262cd 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -106,13 +106,11 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; scpi = sdi->conn; - if (scpi) { - if (sr_scpi_close(scpi) < 0) - return SR_ERR; - sdi->status = SR_ST_INACTIVE; - } - return SR_OK; + if (!scpi) + return SR_ERR_BUG; + + return sr_scpi_close(scpi); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 8e15a20d..9245869b 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -142,11 +142,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return sr_scpi_close(sdi->conn); } static int check_channel_group(struct dev_context *devc, diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 19e42027..f58cfef9 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -219,8 +219,6 @@ static int dev_close(struct sr_dev_inst *sdi) sr_scpi_close(scpi); - sdi->status = SR_ST_INACTIVE; - return SR_OK; } diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index b6a1be5a..0aa012a1 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -282,8 +282,6 @@ static int dev_close(struct sr_dev_inst *sdi) ieee1284_release(sdi->conn); ieee1284_close(sdi->conn); - sdi->status = SR_ST_INACTIVE; - return SR_OK; } diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index d13abf31..b4168513 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -242,13 +242,12 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 8d22fa0b..79585f06 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -221,8 +221,6 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; - sdi->status = SR_ST_INACTIVE; - return scanaplus_close(devc); } diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 02c83e4c..fa50dd69 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -183,8 +183,7 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; /* This allows a frontend to configure the device without ever * doing an acquisition step. */ @@ -195,7 +194,6 @@ static int dev_close(struct sr_dev_inst *sdi) libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 7c7eda9e..9801732a 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -108,13 +108,11 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, LASCAR_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index f177cabd..c3007e42 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -337,15 +337,13 @@ static int dev_close(struct sr_dev_inst *sdi) } if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, 0); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; - return SR_OK; } diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 50094a40..245c421a 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -146,11 +146,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return sr_scpi_close(sdi->conn); } static int config_get(uint32_t key, GVariant **data, diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 451edeb2..23b0e68b 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -215,23 +215,21 @@ static int dev_close(struct sr_dev_inst *sdi) modbus = sdi->conn; - if (modbus) { - devc = sdi->priv; - if (devc->expecting_registers) { - /* Wait for the last data that was requested from the device. */ - uint16_t registers[devc->expecting_registers]; - sr_modbus_read_holding_registers(modbus, -1, - devc->expecting_registers, registers); - } + if (!modbus) + return SR_ERR_BUG; - maynuo_m97_set_bit(modbus, PC1, 0); + devc = sdi->priv; - if (sr_modbus_close(modbus) < 0) - return SR_ERR; - sdi->status = SR_ST_INACTIVE; + if (devc->expecting_registers) { + /* Wait for the last data that was requested from the device. */ + uint16_t registers[devc->expecting_registers]; + sr_modbus_read_holding_registers(modbus, -1, + devc->expecting_registers, registers); } - return SR_OK; + maynuo_m97_set_bit(modbus, PC1, 0); + + return sr_modbus_close(modbus); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 8a0978b8..7dd94f8c 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -420,8 +420,6 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; - sdi->status = SR_ST_INACTIVE; - return p_ols_close(devc); } diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 1e35a541..bd4c7118 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -456,16 +456,13 @@ static int dev_close(struct sr_dev_inst *sdi) scpi = sdi->conn; devc = sdi->priv; + if (!scpi) + return SR_ERR_BUG; + if (devc->model->series->protocol == PROTOCOL_V2) rigol_ds_config_set(sdi, ":KEY:LOCK DISABLE"); - if (scpi) { - if (sr_scpi_close(scpi) < 0) - return SR_ERR; - sdi->status = SR_ST_INACTIVE; - } - - return SR_OK; + return sr_scpi_close(scpi); } static int analog_frame_size(const struct sr_dev_inst *sdi) diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 3ca5441a..d449fddc 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -167,11 +167,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return sr_scpi_close(sdi->conn); } static int config_get(uint32_t key, GVariant **data, diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index 4dcd0aa9..a5b59e4f 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -210,11 +210,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_usb_dev_inst *usb = sdi->conn; - - sr_usb_close(usb); - - sdi->status = SR_ST_INACTIVE; + sr_usb_close(sdi->conn); return SR_OK; } diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index cfddfbb0..ff0af735 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -379,15 +379,15 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; + if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 52b70d3e..707d2626 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -277,15 +277,15 @@ static int dev_close(struct sr_dev_inst *sdi) devc = sdi->priv; scpi = sdi->conn; - if (scpi) { - if (devc->beeper_was_set) - scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_ENABLE); - scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL); - sr_scpi_close(scpi); - sdi->status = SR_ST_INACTIVE; - } - return SR_OK; + if (!scpi) + return SR_ERR_BUG; + + if (devc->beeper_was_set) + scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_ENABLE); + scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL); + + return sr_scpi_close(scpi); } static void clear_helper(void *priv) diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index bb1e9e0b..34dc884d 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -324,8 +324,7 @@ static int dev_open(struct sr_dev_inst *sdi) return ret; } -/* Shutdown and close device. - */ +/* Shutdown and close device. */ static int dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -342,17 +341,16 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_ERR_BUG; } - sdi->status = SR_ST_INACTIVE; - /* Download of the shutdown bitstream, if any. */ ret = (*devc->model->apply_fpga_config)(sdi); if (ret != SR_OK) sr_warn("Unable to shut down device."); libusb_release_interface(usb->devhdl, USB_INTERFACE); + sr_usb_close(usb); - return ret; + return SR_OK; } /* Check whether the device options contain a specific key. diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 933b86ba..548cdb3d 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -171,14 +171,13 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; + if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, 0); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index 15976707..aff78b61 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -108,9 +108,9 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - /* TODO */ + (void)sdi; - sdi->status = SR_ST_INACTIVE; + /* TODO */ return SR_OK; } diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 532d428e..1d12a580 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -136,14 +136,13 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; + if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index b8db2048..66eff890 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -131,13 +131,11 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, VICTOR_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 30b3ca05..606dc2be 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -152,11 +152,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; - - return SR_OK; + return sr_scpi_close(sdi->conn); } /** diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 20804ec9..8d530e57 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -319,7 +319,7 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); @@ -327,7 +327,6 @@ static int dev_close(struct sr_dev_inst *sdi) libusb_reset_device(usb->devhdl); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } diff --git a/src/std.c b/src/std.c index 35da7088..13f9b031 100644 --- a/src/std.c +++ b/src/std.c @@ -174,27 +174,20 @@ SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi) * This function can be used to implement the dev_close() driver API * callback in drivers that use a serial port. * - * After closing the port, the status field of the given sdi is set - * to SR_ST_INACTIVE. - * * @retval SR_OK Success. * @retval SR_ERR_ARG Invalid arguments. + * @retval SR_ERR Serial port close failed. */ SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi) { struct sr_serial_dev_inst *serial; - sdi->status = SR_ST_INACTIVE; - - serial = sdi->conn; - if (!serial) { - sr_err("%s: Can't close invalid serial port.", sdi->driver->name); + if (!sdi || !sdi->conn) return SR_ERR_ARG; - } - serial_close(serial); + serial = sdi->conn; - return SR_OK; + return serial_close(serial); } /**