]> sigrok.org Git - libsigrok.git/commitdiff
rigol-dg: reduce redundancy in malloc() calls
authorGerhard Sittig <redacted>
Sun, 27 Sep 2020 10:09:47 +0000 (12:09 +0200)
committerGerhard Sittig <redacted>
Mon, 28 Sep 2020 07:11:02 +0000 (09:11 +0200)
No need to duplicate the data type, just allocate enough memory to
hold the variable's value. Shuffle the order of items in the array
size calculation (number of items times the size of an item).

src/hardware/rigol-dg/api.c

index 3ae40bcf72aa0f5086bb01988f5ee9113b2a7749..ddc0c72db56e296a61ff2bdb467cdd8cd5554c95 100644 (file)
@@ -181,7 +181,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        if (!device)
                goto error;
 
-       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi = g_malloc0(sizeof(*sdi));
        sdi->vendor = g_strdup(hw_info->manufacturer);
        sdi->model = g_strdup(hw_info->model);
        sdi->version = g_strdup(hw_info->firmware_version);
@@ -190,11 +190,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sdi->driver = &rigol_dg_driver_info;
        sdi->inst_type = SR_INST_SCPI;
 
-       devc = g_malloc0(sizeof(struct dev_context));
+       devc = g_malloc0(sizeof(*devc));
        devc->cmdset = cmdset;
        devc->device = device;
-       devc->ch_status = g_malloc0(sizeof(struct channel_status) *
-                       (device->num_channels + 1));
+       devc->ch_status = g_malloc0((device->num_channels + 1) *
+                       sizeof(devc->ch_status[0]));
        sr_sw_limits_init(&devc->limits);
        sdi->priv = devc;
 
@@ -203,7 +203,7 @@ 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(struct sr_channel_group));
+               cg = g_malloc0(sizeof(*cg));
                snprintf(tmp, sizeof(tmp), "%u", i + 1);
                cg->name = g_strdup(tmp);
                cg->channels = g_slist_append(cg->channels, ch);