From: Gerhard Sittig Date: Wed, 26 Jan 2022 22:23:27 +0000 (+0100) Subject: use common channel group allocation/release code X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d810901a45e01b8e79f6b269dbb931b538071953;p=libsigrok.git use common channel group allocation/release code Eliminate individual open coded alloc and release code for channel groups in hardware drivers and input modules. Use common code instead. This commit affects: arachnid-labs-re-load-pro, atten-pps3xxx, baylibre-acme, dcttech-usbrelay, demo, dreamsourcelab-dslogic, fx2lafw, gwinstek-gds-800, gwinstek-gpd, hameg-hmo, hantek-4032l, hantek-6xxx, hantek-dso, hp-3457a, hp-59306a, hung-chang-dso-2100, itech-it8500, lecroy-xstream, maynuo-m97, microchip-pickit2, motech-lps-30x, rigol-dg, rigol-ds, scpi-pps, siglent-sds, yokogawa-dlm, input/vcd. --- diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index fb6f8272..c14c20d4 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -146,9 +146,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup("1"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + cg = sr_channel_group_new(sdi, "1", NULL); ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V"); cg->channels = g_slist_append(cg->channels, ch); diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index dc6e5201..28b22015 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -157,11 +157,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) for (i = 0; i < MAX_CHANNELS; i++) { snprintf(channel, 10, "CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel); - cg = g_malloc(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel); + cg = sr_channel_group_new(sdi, channel, NULL); cg->channels = g_slist_append(NULL, ch); - cg->priv = NULL; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/baylibre-acme/protocol.c b/src/hardware/baylibre-acme/protocol.c index 89391d54..8d23b9e2 100644 --- a/src/hardware/baylibre-acme/protocol.c +++ b/src/hardware/baylibre-acme/protocol.c @@ -332,9 +332,8 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, if (hwmon < 0) return FALSE; - cg = g_malloc0(sizeof(struct sr_channel_group)); cgp = g_malloc0(sizeof(struct channel_group_priv)); - cg->priv = cgp; + cg = sr_channel_group_new(sdi, NULL, cgp); /* * See if we can read the EEPROM contents. If not, assume it's @@ -380,8 +379,6 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, sr_err("Invalid probe type: %d.", type); } - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); - return TRUE; } diff --git a/src/hardware/dcttech-usbrelay/api.c b/src/hardware/dcttech-usbrelay/api.c index 137277d0..deeb234a 100644 --- a/src/hardware/dcttech-usbrelay/api.c +++ b/src/hardware/dcttech-usbrelay/api.c @@ -63,6 +63,7 @@ static struct sr_dev_inst *probe_device_common(const char *path, struct channel_group_context *cgc; size_t idx, nr; struct sr_channel_group *cg; + char cg_name[24]; /* * Get relay count from product string. Weak condition, @@ -153,12 +154,11 @@ static struct sr_dev_inst *probe_device_common(const char *path, devc->relay_mask = (1U << relay_count) - 1; for (idx = 0; idx < devc->relay_count; idx++) { nr = idx + 1; - cg = g_malloc0(sizeof(*cg)); - cg->name = g_strdup_printf("R%zu", nr); + snprintf(cg_name, sizeof(cg_name), "R%zu", nr); cgc = g_malloc0(sizeof(*cgc)); - cg->priv = cgc; cgc->number = nr; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + cg = sr_channel_group_new(sdi, cg_name, cgc); + (void)cg; } return sdi; diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index ba317fbe..bea35d06 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -151,14 +151,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (num_logic_channels > 0) { /* Logic channels, all in one channel group. */ - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup("Logic"); + cg = sr_channel_group_new(sdi, "Logic", NULL); for (i = 0; i < num_logic_channels; i++) { sprintf(channel_name, "D%d", i); ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); cg->channels = g_slist_append(cg->channels, ch); } - sdi->channel_groups = g_slist_append(NULL, cg); } /* Analog channels, channel groups and pattern generators. */ @@ -173,9 +171,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) pattern = 0; /* An "Analog" channel group with all analog channels in it. */ - acg = g_malloc0(sizeof(struct sr_channel_group)); - acg->name = g_strdup("Analog"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, acg); + acg = sr_channel_group_new(sdi, "Analog", NULL); for (i = 0; i < num_analog_channels; i++) { snprintf(channel_name, 16, "A%d", i); @@ -184,10 +180,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) acg->channels = g_slist_append(acg->channels, ch); /* Every analog channel gets its own channel group as well. */ - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel_name); + cg = sr_channel_group_new(sdi, channel_name, NULL); cg->channels = g_slist_append(NULL, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); /* Every channel gets a generator struct. */ ag = g_malloc(sizeof(struct analog_gen)); diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index 98f4acdb..6d5b7fc7 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -240,15 +240,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->connection_id = g_strdup(connection_id); /* Logic channels, all in one channel group. */ - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup("Logic"); + cg = sr_channel_group_new(sdi, "Logic", NULL); for (j = 0; j < NUM_CHANNELS; j++) { sprintf(channel_name, "%d", j); ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_name); cg->channels = g_slist_append(cg->channels, ch); } - sdi->channel_groups = g_slist_append(NULL, cg); devc = dslogic_dev_new(); devc->profile = prof; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 5acb0016..4665bca2 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -306,15 +306,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0; /* Logic channels, all in one channel group. */ - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup("Logic"); + cg = sr_channel_group_new(sdi, "Logic", NULL); for (j = 0; j < num_logic_channels; j++) { sprintf(channel_name, "D%d", j); ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_name); cg->channels = g_slist_append(cg->channels, ch); } - sdi->channel_groups = g_slist_append(NULL, cg); for (j = 0; j < num_analog_channels; j++) { snprintf(channel_name, 16, "A%d", j); @@ -322,10 +320,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) SR_CHANNEL_ANALOG, TRUE, channel_name); /* Every analog channel gets its own channel group. */ - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel_name); + cg = sr_channel_group_new(sdi, channel_name, NULL); cg->channels = g_slist_append(NULL, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = fx2lafw_dev_new(); diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 22ac40e6..6e9b85bb 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -76,12 +76,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1"); sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2"); - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(""); + cg = sr_channel_group_new(sdi, "", NULL); cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 0)); cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 1)); - cg->priv = NULL; - sdi->channel_groups = g_slist_append(NULL, cg); return sdi; } diff --git a/src/hardware/gwinstek-gpd/api.c b/src/hardware/gwinstek-gpd/api.c index 2b685202..a85be2ed 100644 --- a/src/hardware/gwinstek-gpd/api.c +++ b/src/hardware/gwinstek-gpd/api.c @@ -194,11 +194,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) for (i = 0; i < model->num_channels; i++) { snprintf(channel, sizeof(channel), "CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel); - cg = g_malloc(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel); + cg = sr_channel_group_new(sdi, channel, NULL); cg->channels = g_slist_append(NULL, ch); - cg->priv = NULL; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 26dac0cb..1e9622af 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -1192,6 +1192,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) unsigned int i, j, group; struct sr_channel *ch; struct dev_context *devc; + const char *cg_name; int ret; devc = sdi->priv; @@ -1232,27 +1233,20 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = g_strdup( - (char *)(*scope_models[model_index].analog_names)[i]); + cg_name = (*scope_models[model_index].analog_names)[i]; + devc->analog_groups[i] = sr_channel_group_new(sdi, cg_name, NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } /* Add digital channel groups. */ ret = SR_OK; for (i = 0; i < scope_models[model_index].digital_pods; i++) { - devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); + devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL); if (!devc->digital_groups[i]) { ret = SR_ERR_MALLOC; break; } devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_groups[i]); } if (ret != SR_OK) return ret; diff --git a/src/hardware/hantek-4032l/api.c b/src/hardware/hantek-4032l/api.c index 26a9315e..7e823f8c 100644 --- a/src/hardware/hantek-4032l/api.c +++ b/src/hardware/hantek-4032l/api.c @@ -233,10 +233,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct sr_channel_group *channel_groups[2]; for (int j = 0; j < 2; j++) { - cg = g_malloc0(sizeof(struct sr_channel_group)); + cg = sr_channel_group_new(sdi, NULL, NULL); cg->name = g_strdup_printf("%c", 'A' + j); channel_groups[j] = cg; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } /* Assemble channel list and add channel to channel groups. */ diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 408d1fcd..41a77795 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -140,10 +140,8 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile for (i = 0; i < ARRAY_SIZE(channel_names); i++) { ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel_names[i]); + cg = sr_channel_group_new(sdi, channel_names[i], NULL); cg->channels = g_slist_append(cg->channels, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index a3cc8a28..f0cbb615 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -199,10 +199,8 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) */ for (i = 0; i < ARRAY_SIZE(channel_names); i++) { ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel_names[i]); + cg = sr_channel_group_new(sdi, channel_names[i], NULL); cg->channels = g_slist_append(cg->channels, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 4cfc2d75..9f006df5 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -52,12 +52,9 @@ static int create_front_channel(struct sr_dev_inst *sdi, int chan_idx) TRUE, "Front"); channel->priv = chanc; - front = g_malloc0(sizeof(*front)); - front->name = g_strdup("Front"); + front = sr_channel_group_new(sdi, "Front", NULL); front->channels = g_slist_append(front->channels, channel); - sdi->channel_groups = g_slist_append(sdi->channel_groups, front); - return chan_idx; } @@ -74,10 +71,7 @@ static int create_rear_channels(struct sr_dev_inst *sdi, int chan_idx, if (!card) return chan_idx; - group = g_malloc0(sizeof(*group)); - group->priv = NULL; - group->name = g_strdup(card->cg_name); - sdi->channel_groups = g_slist_append(sdi->channel_groups, group); + group = sr_channel_group_new(sdi, card->cg_name, NULL); for (i = 0; i < card->num_channels; i++) { diff --git a/src/hardware/hp-59306a/api.c b/src/hardware/hp-59306a/api.c index c7a0afca..d2b84004 100644 --- a/src/hardware/hp-59306a/api.c +++ b/src/hardware/hp-59306a/api.c @@ -47,6 +47,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) struct channel_group_context *cgc; size_t idx, nr; struct sr_channel_group *cg; + char cg_name[24]; /* * The device cannot get identified by means of SCPI queries. @@ -73,15 +74,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) devc->channel_count = 6; for (idx = 0; idx < devc->channel_count; idx++) { nr = idx + 1; - - cg = g_malloc0(sizeof(*cg)); - cg->name = g_strdup_printf("R%zu", nr); - + snprintf(cg_name, sizeof(cg_name), "R%zu", nr); cgc = g_malloc0(sizeof(*cgc)); cgc->number = nr; - cg->priv = cgc; - - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + cg = sr_channel_group_new(sdi, cg_name, cgc); + (void)cg; } return sdi; diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index f3d94d20..88423357 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -138,11 +138,9 @@ static GSList *scan_port(GSList *devices, struct parport *port) ieee1284_ref(port); for (i = 0; i < NUM_CHANNELS; i++) { - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(trigger_sources[i]); + cg = sr_channel_group_new(sdi, trigger_sources[i], NULL); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]); cg->channels = g_slist_append(cg->channels, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/itech-it8500/api.c b/src/hardware/itech-it8500/api.c index a720af52..f6156f76 100644 --- a/src/hardware/itech-it8500/api.c +++ b/src/hardware/itech-it8500/api.c @@ -270,9 +270,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->version = g_strdup_printf("%x.%02x", fw_major, fw_minor); sdi->serial_num = unit_serial; - cg = g_malloc0(sizeof(*cg)); - cg->name = g_strdup("1"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + cg = sr_channel_group_new(sdi, "1", NULL); ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1"); cg->channels = g_slist_append(cg->channels, ch); ch = sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "I1"); diff --git a/src/hardware/lecroy-xstream/protocol.c b/src/hardware/lecroy-xstream/protocol.c index a05ff618..8cc2bbd3 100644 --- a/src/hardware/lecroy-xstream/protocol.c +++ b/src/hardware/lecroy-xstream/protocol.c @@ -527,14 +527,9 @@ SR_PRIV int lecroy_xstream_init_device(struct sr_dev_inst *sdi) ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, channel_enabled, (*scope_models[model_index].analog_names)[i]); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = g_strdup( - (char *)(*scope_models[model_index].analog_names)[i]); + devc->analog_groups[i] = sr_channel_group_new(sdi, + (*scope_models[model_index].analog_names)[i], NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } devc->model_config = &scope_models[model_index]; diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 54444d62..20a922fa 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -145,9 +145,7 @@ static struct sr_dev_inst *probe_device(struct sr_modbus_dev_inst *modbus) sdi->driver = &maynuo_m97_driver_info; sdi->inst_type = SR_INST_MODBUS; - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup("1"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + cg = sr_channel_group_new(sdi, "1", NULL); ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1"); cg->channels = g_slist_append(cg->channels, ch); diff --git a/src/hardware/microchip-pickit2/api.c b/src/hardware/microchip-pickit2/api.c index 4eb755d2..d8a75728 100644 --- a/src/hardware/microchip-pickit2/api.c +++ b/src/hardware/microchip-pickit2/api.c @@ -159,9 +159,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->connection_id = g_strdup(conn); /* Create the logic channels group. */ - cg = g_malloc0(sizeof(*cg)); - sdi->channel_groups = g_slist_append(NULL, cg); - cg->name = g_strdup("Logic"); + cg = sr_channel_group_new(sdi, "Logic", NULL); ch_count = ARRAY_SIZE(channel_names); for (ch_idx = 0; ch_idx < ch_count; ch_idx++) { ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC, diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 31bbfa43..b29346ca 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -438,13 +438,9 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o devc->channel_status[cnt].info = g_slist_append(NULL, ch); - cg = g_malloc(sizeof(struct sr_channel_group)); snprintf(channel, sizeof(channel), "CG%d", cnt + 1); - cg->name = g_strdup(channel); - cg->priv = NULL; + cg = sr_channel_group_new(sdi, channel, NULL); cg->channels = g_slist_append(NULL, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } /* Query status */ diff --git a/src/hardware/rigol-dg/api.c b/src/hardware/rigol-dg/api.c index e8a3aadc..a1732432 100644 --- a/src/hardware/rigol-dg/api.c +++ b/src/hardware/rigol-dg/api.c @@ -380,12 +380,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) for (i = 0; i < device->num_channels; i++) { ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG, TRUE, device->channels[i].name); - cg = g_malloc0(sizeof(*cg)); snprintf(tmp, sizeof(tmp), "%u", i + 1); - cg->name = g_strdup(tmp); + cg = sr_channel_group_new(sdi, tmp, NULL); cg->channels = g_slist_append(cg->channels, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } /* Create channels for the frequency counter output. */ diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 632c9596..aab47302 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -395,17 +395,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) channel_name = g_strdup_printf("CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = channel_name; + devc->analog_groups[i] = sr_channel_group_new(sdi, + channel_name, NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } if (devc->model->has_digital) { - devc->digital_group = g_malloc0(sizeof(struct sr_channel_group)); - + devc->digital_group = sr_channel_group_new(sdi, "LA", NULL); for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { channel_name = g_strdup_printf("D%d", i); ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); @@ -413,9 +409,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); } - devc->digital_group->name = g_strdup("LA"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_group); } for (i = 0; i < ARRAY_SIZE(timebases); i++) { diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index aa5b945a..bd11f082 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -145,8 +145,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi, for (i = 0; i < num_channel_groups; i++) { cgs = &channel_groups[i]; - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(cgs->name); + cg = sr_channel_group_new(sdi, cgs->name, NULL); for (j = 0, mask = 1; j < 64; j++, mask <<= 1) { if (cgs->channel_index_mask & mask) { for (l = sdi->channels; l; l = l->next) { @@ -167,7 +166,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi, pcg = g_malloc0(sizeof(struct pps_channel_group)); pcg->features = cgs->features; cg->priv = pcg; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } sr_scpi_hw_info_free(hw_info); diff --git a/src/hardware/siglent-sds/api.c b/src/hardware/siglent-sds/api.c index 846399b6..76955e6d 100644 --- a/src/hardware/siglent-sds/api.c +++ b/src/hardware/siglent-sds/api.c @@ -305,17 +305,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) channel_name = g_strdup_printf("CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = channel_name; + devc->analog_groups[i] = sr_channel_group_new(sdi, + channel_name, NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } if (devc->model->has_digital) { - devc->digital_group = g_malloc0(sizeof(struct sr_channel_group)); - + devc->digital_group = sr_channel_group_new(sdi, "LA", NULL); for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { channel_name = g_strdup_printf("D%d", i); ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); @@ -323,9 +319,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); } - devc->digital_group->name = g_strdup("LA"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_group); } for (i = 0; i < ARRAY_SIZE(timebases); i++) { diff --git a/src/hardware/yokogawa-dlm/protocol.c b/src/hardware/yokogawa-dlm/protocol.c index d2c51cda..06dae50f 100644 --- a/src/hardware/yokogawa-dlm/protocol.c +++ b/src/hardware/yokogawa-dlm/protocol.c @@ -790,24 +790,17 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index) ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = g_strdup( - (char *)(*scope_models[model_index].analog_names)[i]); + devc->analog_groups[i] = sr_channel_group_new(sdi, + (*scope_models[model_index].analog_names)[i], NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } /* Add digital channel groups. */ for (i = 0; i < scope_models[model_index].pods; i++) { - devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); + devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL); if (!devc->digital_groups[i]) return SR_ERR_MALLOC; devc->digital_groups[i]->name = g_strdup_printf("POD%d", i); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_groups[i]); } /* Add digital channels. */ diff --git a/src/input/vcd.c b/src/input/vcd.c index 41371230..acd30e5d 100644 --- a/src/input/vcd.c +++ b/src/input/vcd.c @@ -205,15 +205,6 @@ static void free_channel(void *data) g_free(vcd_ch); } -/* TODO Drop the local decl when this has become a common helper. */ -void sr_channel_group_free(struct sr_channel_group *cg); - -/* Wrapper for GDestroyNotify compatibility. */ -static void cg_free(void *p) -{ - sr_channel_group_free(p); -} - /* * Another timestamp delta was observed, update statistics: Update the * sorted list of minimum values, and increment the occurance counter. @@ -1074,10 +1065,8 @@ static void create_channels(const struct sr_input *in, if (vcd_ch->type != ch_type) continue; cg = NULL; - if (vcd_ch->size != 1) { - cg = g_malloc0(sizeof(*cg)); - cg->name = g_strdup(vcd_ch->name); - } + if (vcd_ch->size != 1) + cg = sr_channel_group_new(sdi, vcd_ch->name, NULL); for (size_idx = 0; size_idx < vcd_ch->size; size_idx++) { ch_name = get_channel_name(vcd_ch, size_idx); sr_dbg("sigrok channel idx %zu, name %s, type %s, en %d.", @@ -1089,8 +1078,6 @@ static void create_channels(const struct sr_input *in, if (cg) cg->channels = g_slist_append(cg->channels, ch); } - if (cg) - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } } @@ -1135,7 +1122,7 @@ static void keep_header_for_reread(const struct sr_input *in) inc = in->priv; - g_slist_free_full(inc->prev.sr_groups, cg_free); + g_slist_free_full(inc->prev.sr_groups, sr_channel_group_free_cb); inc->prev.sr_groups = in->sdi->channel_groups; in->sdi->channel_groups = NULL; @@ -1174,7 +1161,7 @@ static gboolean check_header_in_reread(const struct sr_input *in) return FALSE; } - g_slist_free_full(in->sdi->channel_groups, cg_free); + g_slist_free_full(in->sdi->channel_groups, sr_channel_group_free_cb); in->sdi->channel_groups = inc->prev.sr_groups; inc->prev.sr_groups = NULL;