]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/brymen-bm86x/api.c
sr_dev_close(): Set status to SR_ST_INACTIVE.
[libsigrok.git] / src / hardware / brymen-bm86x / api.c
index 2edade93d28688b87821c1d7cff5f67eb3048413..23b42e1390cddee7c0baee502e50d8c2d9fe47db 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)
@@ -131,32 +129,23 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        usb = sdi->conn;
        devc = sdi->priv;
 
        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,
@@ -176,9 +165,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        return sr_sw_limits_config_set(&devc->sw_limits, key, data);