]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds1xx2: Use std_dev_clear().
authorUwe Hermann <redacted>
Fri, 31 May 2013 13:19:53 +0000 (15:19 +0200)
committerUwe Hermann <redacted>
Sun, 2 Jun 2013 11:52:40 +0000 (13:52 +0200)
hardware/rigol-ds1xx2/api.c

index a6bdff27b9540a225a064f4ba909cbda3fa58d5b..81ea66950c06a560d2868fa0ac2ef18d80913729 100644 (file)
@@ -140,37 +140,21 @@ static const char *supported_models[] = {
 SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
 static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
 
-/* Properly close and free all devices. */
-static int clear_instances(void)
+static void clear_helper(void *priv)
 {
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
        struct dev_context *devc;
-       GSList *l;
 
-       if (!(drvc = di->priv))
-               return SR_OK;
+       devc = priv;
 
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data))
-                       continue;
-
-               if (sdi->conn)
-                       sr_serial_dev_inst_free(sdi->conn);
-
-               if ((devc = sdi->priv)) {
-                       g_free(devc->coupling[0]);
-                       g_free(devc->coupling[1]);
-                       g_free(devc->trigger_source);
-                       g_free(devc->trigger_slope);
-               }
-               sr_dev_inst_free(sdi);
-       }
-
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
+       g_free(devc->coupling[0]);
+       g_free(devc->coupling[1]);
+       g_free(devc->trigger_source);
+       g_free(devc->trigger_slope);
+}
 
-       return SR_OK;
+static int clear_instances(void)
+{
+       return std_dev_clear(di, clear_helper);
 }
 
 static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
@@ -266,6 +250,7 @@ static int probe_port(const char *port, GSList **devices)
        if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL)))
                return SR_ERR_MALLOC;
        sdi->driver = di;
+       sdi->inst_type = SR_INST_SERIAL;
 
        if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
                return SR_ERR_MALLOC;
@@ -379,9 +364,7 @@ static int dev_close(struct sr_dev_inst *sdi)
 
 static int cleanup(void)
 {
-       clear_instances();
-
-       return SR_OK;
+       return clear_instances();
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)