rigol-ds1xx2: Use std_dev_clear().

This commit is contained in:
Uwe Hermann 2013-05-31 15:19:53 +02:00
parent dec6c583a2
commit fa85f37630
1 changed files with 15 additions and 32 deletions

View 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;
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)