]> sigrok.org Git - libsigrok.git/commitdiff
sr_dev_open(): Set status to SR_ST_ACTIVE upon success.
authorUwe Hermann <redacted>
Fri, 7 Jul 2017 20:36:24 +0000 (22:36 +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/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/protocol.c
src/hardware/ftdi-la/api.c
src/hardware/fx2lafw/protocol.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/hameg-hmo/api.c
src/hardware/hantek-6xxx/protocol.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-xstream/api.c
src/hardware/link-mso19/api.c
src/hardware/maynuo-m97/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/pipistrello-ols/protocol.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 e5cbf4ef2868473e1c689e0752361d5f9e35c998..14b56b2f33a2ed269c95d8bcaeceb85e9c6fc3e8 100644 (file)
@@ -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;
 }
 
index 676be07f2d0f86e122d461f1241dc2f9e448dde3..50a1d489ed51fa22d03a9778f1426afed2ce0b34 100644 (file)
@@ -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;
 }
 
index c00c37985fa6e538378d0effea684c333d7c33d6..fff5e8da0dbd3ceaf97b282bab83959ab1142aab 100644 (file)
@@ -130,8 +130,6 @@ static int dev_open(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
index 0d022f2b336967e0aea956071d21ca92589c55eb..d8329897a543267d8f4838bbdea207435031aa3d 100644 (file)
@@ -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;
 }
 
index cafba7da33e0a6b6c833ccc0e2e074486734ea61..44424241d945f66174b931861f176df08b4e74d0 100644 (file)
@@ -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)
index 9f793969464261fd113e1651cec8ea572313809f..1bfc82e66574e55ee86c729e72d2b3432c6a99e7 100644 (file)
@@ -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)
index 236bb316225898f04e4a860c6cc7a0ab6f200e0a..3f4ae41ef0590b8590119e4a96a24ab78c584a5e 100644 (file)
@@ -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;
 }
index 43280cc56333e44586ebaee608e8cf07cca6783b..77d1e0ef6aab6f10c058f0c69a5e5dc66d528c65 100644 (file)
@@ -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)
index 9aac98aebb87b3cbd0d87d8943d54330f7e32ec4..3a3a88610288b0b3d87d10eaae21242ded31ea57 100644 (file)
@@ -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;
 }
 
index 422c84ea3f693abf4445d7f6f9f836389edd63e2..e88bbd2fd6fa47e7dcda8e7d700993c3cd719ce5 100644 (file)
@@ -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)
index 2ab06957e2ed39e98a2e2a74d7888a7f30bb8b59..30407c3f4c61fa18b7c651cf68c4149a20589005 100644 (file)
@@ -98,8 +98,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
index 20b5779c1968badbbfb29e4cca0902aabdb8946a..8e15a20d6d21bf9276c5f9fbbcdb8d59323f0b12 100644 (file)
@@ -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;
 }
 
index a08e126c5e32a9fc7f672b23d379ac6eeabfe57c..8e406ffe03f04db5220cfccc18653ac10b72d024 100644 (file)
@@ -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)
index 195b9804f8ed081f0f820a5eebcc3dd9e213afd0..19e42027cdb79b3aeec15b8e8983d3ad98ad8eae 100644 (file)
@@ -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;
 }
 
index 9f7526172d7c0ed95c650bd17766ebb962ffc5a2..b6a1be5a2ad25c6093e164d732cbd7c71d06b258 100644 (file)
@@ -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:
index 66be858fac2376fbf093e90e58f1c45d66876012..d13abf310ed159c011f9ad8e4da26a12fe7cdbf8 100644 (file)
@@ -232,8 +232,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
index 1bc17b73528c226979a9b0d353004fa2302dd0b1..8d22fa0b49a89f1a9e51b7ad088b1eb80898be37 100644 (file)
@@ -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;
 }
 
index 07d71f48f06d7ce4b7d74ad9a960f5c6b05738e9..02c83e4c055c12322670c5df21a60f7aad7f3f90 100644 (file)
@@ -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)
index 44d7643f08cd2aaf656227c5044dd57e8b1b83fc..7c7eda9e68858847825a96fbad6728fd9f91a093 100644 (file)
@@ -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)
index 075fff76fb9816d11e5a2ceab2ba83f33167a606..50094a406294355d8071f28c547862728b755ac3 100644 (file)
@@ -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;
 }
 
index 241d5e0a6d2f798c363a8995f02bc531e27836f1..5924aeb956edbe228c8b640355a967f536112c90 100644 (file)
@@ -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);
index 970bfe95615c3fb069067fc04d6c332c12d57d0c..451edeb29f923f4a6e6949d882045d8d61fade73 100644 (file)
@@ -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;
index 5995cdf87f69cb21ccd1f81a56883f64f15bf2f0..8a0978b8f5d1c2b039bbe56aa891386c24138d70 100644 (file)
@@ -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)
index 8276a9ed46f83aee4fb7ec4231ecc2a671a2e13f..aaff51150f15fdb138c5705b37b1ce0210afa072 100644 (file)
@@ -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;
 }
 
index 9fb2f4066fd148698b60f6fb091d178feb8760b3..1e35a5419798363b9c54e2eefaa4f8888990cc3c 100644 (file)
@@ -445,8 +445,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
index 7d39cbdfe54f23b3443efac66b34ca8c9e3c4a99..3ca5441ad2fb2ad6d91e2f500a47220033f23171 100644 (file)
@@ -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)
index a456d0b652fb20a0de97da9d1c2dca3c22286720..4dcd0aa9221139a2d3e12af473eba5002eb9e829 100644 (file)
@@ -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;
 }
 
index 986b02571d6617998d2a9e3ad92d7b9295c975c5..cfddfbb082d0fb990596f6af627f4eb768e60ae3 100644 (file)
@@ -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);
index 50eabc9f4f7b3ccb254e5409a5802b0b34578373..52b70d3e0adf5a6f582b23004e3ed312b20bf986 100644 (file)
@@ -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;
index 59b368196ff749acd2a18f91ca842f7c7e461ad6..bb1e9e0b48719c1fa98eb3a36ac762e36a7e74d5 100644 (file)
@@ -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);
        }
 
index bc21f0f97d1f105bfc9065acc790cfd50657e81d..933b86bae7b4b02fd2f50e45895634f7f4f90e31 100644 (file)
@@ -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;
 }
index c6e0dd9adcbc59d5180037d811e6cab9019b2b38..15976707a5697e03b19c8660a1f02e4b055e00ad 100644 (file)
@@ -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)
index b340e40fcf860597df1c5400993d9e4493a2f7bb..532d428e151480d605d6abd9c0b22dc41ba3a65c 100644 (file)
@@ -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)
index 0b96a5d298d644507f85962577f2eabec956e5e7..b8db20483562486cbe983ea046c2b60cd66d9162 100644 (file)
@@ -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;
 }
index 2faf7917cd05d89a85ab0c32fb9bbda1cc4c8f15..30b3ca05945b5a00f0173da1a7c64225e9286783 100644 (file)
@@ -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;
 }
 
index 7803407a21ce9c5d6bbacfd6ff747a34a20412eb..20804ec9a5bf1e2ac9ebf70c6703d46f9ef8a5c5 100644 (file)
@@ -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.",
index ccb73718c9b26b0fdf129b43439f437c5405e414..35da70884a700a8256f461480c4a6223d1c9c7ce 100644 (file)
--- 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);
 }
 
 /**