]> sigrok.org Git - libsigrok.git/commitdiff
use common channel group allocation/release code
authorGerhard Sittig <redacted>
Wed, 26 Jan 2022 22:23:27 +0000 (23:23 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:54 +0000 (18:53 +0100)
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.

27 files changed:
src/hardware/arachnid-labs-re-load-pro/api.c
src/hardware/atten-pps3xxx/api.c
src/hardware/baylibre-acme/protocol.c
src/hardware/dcttech-usbrelay/api.c
src/hardware/demo/api.c
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/fx2lafw/api.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/gwinstek-gpd/api.c
src/hardware/hameg-hmo/protocol.c
src/hardware/hantek-4032l/api.c
src/hardware/hantek-6xxx/api.c
src/hardware/hantek-dso/api.c
src/hardware/hp-3457a/api.c
src/hardware/hp-59306a/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/itech-it8500/api.c
src/hardware/lecroy-xstream/protocol.c
src/hardware/maynuo-m97/api.c
src/hardware/microchip-pickit2/api.c
src/hardware/motech-lps-30x/api.c
src/hardware/rigol-dg/api.c
src/hardware/rigol-ds/api.c
src/hardware/scpi-pps/api.c
src/hardware/siglent-sds/api.c
src/hardware/yokogawa-dlm/protocol.c
src/input/vcd.c

index fb6f82727dedd9eafe515a5b27310bed96c6075d..c14c20d400d05db58c3c55b32680f91893666b8e 100644 (file)
@@ -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);
index dc6e5201977d30769956521c1450ffebfd8eb8b4..28b22015d3fd13f449c0379cf7f84d92b5e8363b 100644 (file)
@@ -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));
index 89391d5482286e541873910e457be935b6e7818b..8d23b9e2f9875d36093115c52b1911c3e1ac1e2a 100644 (file)
@@ -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;
 }
 
index 137277d0176b014758883bba82d988cd1c58a985..deeb234a95eb2e72e640e6a3d0bcc8e2b9e328a6 100644 (file)
@@ -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;
index ba317fbe4a1b8fa389a8de39966c833956820659..bea35d068f63042a04fd7b27b6d691f3778ad0fb 100644 (file)
@@ -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));
index 98f4acdb159269efed773f517a18d96f9e119503..6d5b7fc7d6cd009d5bf90c8f043fa0cc28162993 100644 (file)
@@ -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;
index 5acb0016d0b8e6ab5ad204aea7e238f55e2f5fa8..4665bca2419deae0f0347e6e2aa5039462ef04d0 100644 (file)
@@ -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();
index 22ac40e6c77ef0192e64601f24d53abf8aecd00c..6e9b85bbbb6d89374cf71e43cd3e67cedf03fc21 100644 (file)
@@ -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;
 }
index 2b685202733612b8e6db6262f47841c8080b69bf..a85be2ed3d433746338580b0544e0aecac5ccbe9 100644 (file)
@@ -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));
index 26dac0cb037f34de3a8e370bc2d74a99285a799d..1e9622af16db9329de6bc827678202cb20737f53 100644 (file)
@@ -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;
index 26a9315e5035024c9559f679a950576a72246b95..7e823f8c7935cb9eb1422fcc6e1fdb5b389f991c 100644 (file)
@@ -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. */
index 408d1fcdcc03ec026edd2a57ba9c140855d7c9d2..41a77795cee84ed5916457b3bc156b8240ccf2c0 100644 (file)
@@ -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));
index a3cc8a283304ae233ebb1c857ad13eb08be2e094..f0cbb6158276048186c11a6e970f76adb6b683ce 100644 (file)
@@ -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));
index 4cfc2d758b54e79625609d408ef0f506d028a5b7..9f006df5600f43889b8a58bfde775c079c49c14d 100644 (file)
@@ -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++) {
 
index c7a0afca5b2ad34d11309313754c0aa0a5fbb45e..d2b840041d36dc227979f5b6dfde0a8f353372a4 100644 (file)
@@ -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;
index f3d94d2003d386de64760e37d31d4499f20b2bb0..88423357592dd6eeefa230abf980ddab09015fbf 100644 (file)
@@ -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));
index a720af5207aea98f414025aa983c4ed91f092e18..f6156f761de6d72bd0dc03c1099fc6161275dec8 100644 (file)
@@ -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");
index a05ff618d5e4c8eeaa1877f6fc46b6ada7ac7875..8cc2bbd3b060c03b99f9fb49465c7fc5000848bd 100644 (file)
@@ -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];
index 54444d623c6d1484bfbe31f3da3d99d512a91c33..20a922fa215177a139587c94121693ec6bac45a0 100644 (file)
@@ -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);
index 4eb755d274d057e3eae731e378c8f815b9589e4e..d8a757283655496d10b9a2c2d26eed2c7c875694 100644 (file)
@@ -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,
index 31bbfa43827f6c75fecb628bb461f093592fd51e..b29346ca1cbcab166b6e37d6210ed08b11bec310 100644 (file)
@@ -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 */
index e8a3aadc8acd4ea2fd8edaa2824bb114abb42f31..a173243264576e2a0ff6e8859d03e240f464f080 100644 (file)
@@ -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. */
index 632c95963cb75e517e6d7abe3cbff783e6cbee70..aab4730265d892e4d158cf0ed9d233452495567e 100644 (file)
@@ -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++) {
index aa5b945a3349cee0573491709d304efa424ccdc7..bd11f082ae78709fe1b36b8cec1545a28fbadfe5 100644 (file)
@@ -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);
index 846399b678c4a8a3af56864e99ffbf27173b9d87..76955e6da058c211a173b36cfd5beebf40a2bed4 100644 (file)
@@ -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++) {
index d2c51cdac6d4f5ebfebaf61c02c66dfef262d9cb..06dae50f7cd9a3979692371138df4ad8b91b3f0b 100644 (file)
@@ -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. */
index 413712301318787f7201f9389de5748418dbfbeb..acd30e5d7f05ae91420453b221f7b4176d111a69 100644 (file)
@@ -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;