From: Uwe Hermann Date: Fri, 31 May 2013 13:19:53 +0000 (+0200) Subject: rigol-ds1xx2: Use std_dev_clear(). X-Git-Tag: libsigrok-0.2.1~79 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fa85f376301dd43232032867f8df834e746060c6;p=libsigrok.git rigol-ds1xx2: Use std_dev_clear(). --- diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index a6bdff27..81ea6695 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -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)