]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/sysclk-lwla/api.c
dev_clear(): Consistently name callback 'clear_helper()'.
[libsigrok.git] / src / hardware / sysclk-lwla / api.c
index 439d71f27b2d02896b12979c76d6526cefd32d66..6cd38a13a05a41891401ff60d13dc3636585d0fa 100644 (file)
@@ -203,9 +203,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        return std_scan_complete(di, devices);
 }
 
-/* Destroy the private device context.
- */
-static void clear_dev_context(void *priv)
+static void clear_helper(void *priv)
 {
        struct dev_context *devc;
 
@@ -215,16 +213,13 @@ static void clear_dev_context(void *priv)
                sr_err("Cannot clear device context during acquisition!");
                return; /* Leak and pray. */
        }
-       sr_dbg("Device context cleared.");
 
        g_free(devc);
 }
 
-/* Destroy all device instances.
- */
 static int dev_clear(const struct sr_dev_driver *di)
 {
-       return std_dev_clear(di, &clear_dev_context);
+       return std_dev_clear_with_callback(di, clear_helper);
 }
 
 /* Drain any pending data from the USB transfer buffers on the device.
@@ -273,11 +268,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status != SR_ST_INACTIVE) {
-               sr_err("Device already open.");
-               return SR_ERR;
-       }
-
        /* Try the whole shebang three times, fingers crossed. */
        for (i = 0; i < 3; i++) {
                ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
@@ -308,8 +298,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;
@@ -322,7 +310,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                        break;
 
                /* Rinse and repeat. */
-               sdi->status = SR_ST_INACTIVE;
                sr_usb_close(usb);
        }
 
@@ -332,8 +319,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;
@@ -343,10 +329,6 @@ static int dev_close(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_INACTIVE) {
-               sr_dbg("Device already closed.");
-               return SR_OK;
-       }
        if (devc->acquisition) {
                sr_err("Cannot close device during acquisition!");
                /* Request stop, leak handle, and prepare for the worst. */
@@ -354,17 +336,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.
@@ -645,9 +626,6 @@ static int config_commit(const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        if (devc->acquisition) {
                sr_err("Acquisition still in progress?");
                return SR_ERR;