]> sigrok.org Git - libsigrok.git/blobdiff - src/device.c
sr_dev_close(): Factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / device.c
index a8f6f2b4dce9c0695961cbd1ec618f4d5f201ab3..6eff16d16573e45c78f0e836a168ff72ff15d31f 100644 (file)
@@ -136,7 +136,9 @@ SR_API int sr_dev_channel_enable(struct sr_channel *channel, gboolean state)
 }
 
 /* Returns the next enabled channel, wrapping around if necessary. */
+/** @private */
 SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
+
                struct sr_channel *cur_channel)
 {
        struct sr_channel *next_channel;
@@ -489,6 +491,9 @@ SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device)
 /** @private */
 SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc)
 {
+       if (!usbtmc)
+               return;
+
        g_free(usbtmc->device);
        g_free(usbtmc);
 }
@@ -576,6 +581,14 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi)
        if (!sdi || !sdi->driver || !sdi->driver->dev_close)
                return SR_ERR;
 
+       if (sdi->status != SR_ST_ACTIVE) {
+               sr_err("%s: Device instance not active, can't close.",
+                       sdi->driver->name);
+               return SR_ERR_DEV_CLOSED;
+       }
+
+       sr_dbg("%s: Closing device.", sdi->driver->name)
+
        ret = sdi->driver->dev_close(sdi);
 
        return ret;