]> sigrok.org Git - libsigrok.git/commitdiff
sr_dev_close(): Set status to SR_ST_INACTIVE.
authorUwe Hermann <redacted>
Fri, 7 Jul 2017 18:42:04 +0000 (20:42 +0200)
committerUwe Hermann <redacted>
Sat, 8 Jul 2017 12:25:23 +0000 (14:25 +0200)
This ensures consistent checks and log messages across all drivers
and reduces the per-driver boilerplate.

37 files changed:
src/device.c
src/hardware/asix-sigma/api.c
src/hardware/atten-pps3xxx/api.c
src/hardware/baylibre-acme/api.c
src/hardware/beaglelogic/api.c
src/hardware/brymen-bm86x/api.c
src/hardware/chronovu-la/api.c
src/hardware/demo/api.c
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/ftdi-la/api.c
src/hardware/fx2lafw/api.c
src/hardware/gmc-mh-1x-2x/api.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/hameg-hmo/api.c
src/hardware/hp-3457a/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/ikalogic-scanaplus/api.c
src/hardware/kecheng-kc-330b/api.c
src/hardware/lascar-el-usb/api.c
src/hardware/lecroy-logicstudio/api.c
src/hardware/lecroy-xstream/api.c
src/hardware/maynuo-m97/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/rigol-ds/api.c
src/hardware/rohde-schwarz-sme-0x/api.c
src/hardware/saleae-logic-pro/api.c
src/hardware/saleae-logic16/api.c
src/hardware/scpi-pps/api.c
src/hardware/sysclk-lwla/api.c
src/hardware/testo/api.c
src/hardware/uni-t-dmm/api.c
src/hardware/uni-t-ut32x/api.c
src/hardware/victor-dmm/api.c
src/hardware/yokogawa-dlm/api.c
src/hardware/zeroplus-logic-cube/api.c
src/std.c

index 14b56b2f33a2ed269c95d8bcaeceb85e9c6fc3e8..9ba8bfc570cb43ed9bec54a661904b45ec6f7e88 100644 (file)
@@ -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);
 
index 50a1d489ed51fa22d03a9778f1426afed2ce0b34..41a775a53254b502214ce4e5da521da50c8fb3cd 100644 (file)
@@ -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,
index 6458ebf4b3bf4e04f6cf5ac80bdc737cbe962b36..59252838341836e71658cc260657ea0160d89fda 100644 (file)
@@ -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
index fff5e8da0dbd3ceaf97b282bab83959ab1142aab..c45ab77d1da29715c4b7a1310fee35e0ef02ae14 100644 (file)
@@ -137,8 +137,6 @@ static int dev_close(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       sdi->status = SR_ST_INACTIVE;
-
        return SR_OK;
 }
 
index d8329897a543267d8f4838bbdea207435031aa3d..ff8f0424d32049c834a365fe8eefa03c0e4dfe48 100644 (file)
@@ -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;
 }
 
index 44424241d945f66174b931861f176df08b4e74d0..23b42e1390cddee7c0baee502e50d8c2d9fe47db 100644 (file)
@@ -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,
index 1bfc82e66574e55ee86c729e72d2b3432c6a99e7..0c94b398586629a57659310720cdfa5acc0b4e7e 100644 (file)
@@ -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,
index 3f4ae41ef0590b8590119e4a96a24ab78c584a5e..0dd0a38a6b65e4b6c9c73307f32a5e3dd25186f0 100644 (file)
@@ -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;
 }
index e9e4450272631b2e68807ade9c325049153b1d05..d11861bbdae876bbaeee495a756aadd79e13946e 100644 (file)
@@ -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;
 }
index 3a3a88610288b0b3d87d10eaae21242ded31ea57..5a7ac51e52801b9184126cca558534dca2322f52 100644 (file)
@@ -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;
 }
index 879fdf04ae1bfce2d4d05c49411657b9043e7d2d..547f7229d4169c0741879d60857f7e28d9ef994e 100644 (file)
@@ -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;
 }
index 992cbd8124faf3561857019690d431b21e7ec6b5..8bac10f14c7cc10e48a9f3cf580512af3646fbf8 100644 (file)
@@ -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,
index 30407c3f4c61fa18b7c651cf68c4149a20589005..0b8262cdebb053175012e3b1f5a301e70f676c76 100644 (file)
@@ -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,
index 8e15a20d6d21bf9276c5f9fbbcdb8d59323f0b12..9245869b35b2cb7f167fe2d26726062c13769359 100644 (file)
@@ -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,
index 19e42027cdb79b3aeec15b8e8983d3ad98ad8eae..f58cfef90cc9774ea71e75bb37d6ad740c7224c0 100644 (file)
@@ -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;
 }
 
index b6a1be5a2ad25c6093e164d732cbd7c71d06b258..0aa012a1a3b54e90d1ed3a15137aa565e8eefac0 100644 (file)
@@ -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;
 }
 
index d13abf310ed159c011f9ad8e4da26a12fe7cdbf8..b4168513c66b68cb887ba1321c87b7c9ab50a4c6 100644 (file)
@@ -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;
 }
index 8d22fa0b49a89f1a9e51b7ad088b1eb80898be37..79585f060dfc86f9d71209cd27f2567611bd7f82 100644 (file)
@@ -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);
 }
 
index 02c83e4c055c12322670c5df21a60f7aad7f3f90..fa50dd698d7a56400e6fa890080404052657077c 100644 (file)
@@ -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;
 }
index 7c7eda9e68858847825a96fbad6728fd9f91a093..9801732a8e70ce1211757abf7030dc9eb029f6f8 100644 (file)
@@ -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;
 }
index f177cabd129cd9eb947ebce69989d58308d6ad4b..c3007e4210da344695493dd71a17408bb4819663 100644 (file)
@@ -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;
 }
 
index 50094a406294355d8071f28c547862728b755ac3..245c421a967484f67d5fa5292575fd53b145e72b 100644 (file)
@@ -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,
index 451edeb29f923f4a6e6949d882045d8d61fade73..23b0e68bc14b63788c1cb581e261849717a373a0 100644 (file)
@@ -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,
index 8a0978b8f5d1c2b039bbe56aa891386c24138d70..7dd94f8c355dc5dfd418972e95aab27ef76914c4 100644 (file)
@@ -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);
 }
 
index 1e35a5419798363b9c54e2eefaa4f8888990cc3c..bd4c71181264907c8df6f8c09220b6d02ccb4f68 100644 (file)
@@ -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)
index 3ca5441ad2fb2ad6d91e2f500a47220033f23171..d449fddc58642b19e70161e045c9741e20e19da4 100644 (file)
@@ -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,
index 4dcd0aa9221139a2d3e12af473eba5002eb9e829..a5b59e4f61685245cc4c8eeb88be7440978f537e 100644 (file)
@@ -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;
 }
index cfddfbb082d0fb990596f6af627f4eb768e60ae3..ff0af73532dbd09389bdd776ac1e03970e87b8ce 100644 (file)
@@ -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;
 }
index 52b70d3e0adf5a6f582b23004e3ed312b20bf986..707d26263198c4f039c8d61b73e1a5ef49957325 100644 (file)
@@ -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)
index bb1e9e0b48719c1fa98eb3a36ac762e36a7e74d5..34dc884d83e58a89d573a6be8d78115288492d4c 100644 (file)
@@ -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.
index 933b86bae7b4b02fd2f50e45895634f7f4f90e31..548cdb3d8107865b32b5184cb7dead8d6294d369 100644 (file)
@@ -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;
 }
index 15976707a5697e03b19c8660a1f02e4b055e00ad..aff78b61d8454441c74392a8f8b9edeb1036d8ce 100644 (file)
@@ -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;
 }
index 532d428e151480d605d6abd9c0b22dc41ba3a65c..1d12a580a76fbdd844520b1dcc3f111cf08c5504 100644 (file)
@@ -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;
 }
index b8db20483562486cbe983ea046c2b60cd66d9162..66eff890a107ea39b3e76070e54abae070a7b3aa 100644 (file)
@@ -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;
 }
index 30b3ca05945b5a00f0173da1a7c64225e9286783..606dc2be03f3bacf84a3aa31d97f509cea3a0438 100644 (file)
@@ -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);
 }
 
 /**
index 20804ec9a5bf1e2ac9ebf70c6703d46f9ef8a5c5..8d530e5779dc6877d1c9d9e9d43bfa188bd6e389 100644 (file)
@@ -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;
 }
index 35da70884a700a8256f461480c4a6223d1c9c7ce..13f9b03195f549eafa40e02072605242dc6f7294 100644 (file)
--- 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);
 }
 
 /**