]> sigrok.org Git - libsigrok.git/commitdiff
rdtech-tc: eliminate redundant type info in malloc call
authorGerhard Sittig <redacted>
Thu, 16 Mar 2023 02:25:00 +0000 (03:25 +0100)
committerGerhard Sittig <redacted>
Thu, 16 Mar 2023 13:29:30 +0000 (14:29 +0100)
Allocate whatever it takes to hold the variable. Don't open code the
type information again when inconsistency would go unnoticed.

Link devc earlier to sdi, ideally immediately after allocation.

src/hardware/rdtech-tc/api.c

index 2bb2cab520a5be39e3f7338878d34103016fb6fc..0ceff987cfcc27fbba851c5e57c1e5c57e30c31b 100644 (file)
@@ -59,7 +59,7 @@ static GSList *rdtech_tc_scan(struct sr_dev_driver *di,
        if (serial_open(serial, SERIAL_RDWR) != SR_OK)
                goto err_out;
 
-       devc = g_malloc0(sizeof(struct dev_context));
+       devc = g_malloc0(sizeof(*devc));
        sr_sw_limits_init(&devc->limits);
 
        if (rdtech_tc_probe(serial, devc) != SR_OK) {
@@ -67,7 +67,8 @@ static GSList *rdtech_tc_scan(struct sr_dev_driver *di,
                goto err_out_serial;
        }
 
-       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi = g_malloc0(sizeof(*sdi));
+       sdi->priv = devc;
        sdi->status = SR_ST_INACTIVE;
        sdi->vendor = g_strdup("RDTech");
        sdi->model = g_strdup(devc->dev_info.model_name);
@@ -75,7 +76,6 @@ static GSList *rdtech_tc_scan(struct sr_dev_driver *di,
        sdi->serial_num = g_strdup_printf("%08" PRIu32, devc->dev_info.serial_num);
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
-       sdi->priv = devc;
 
        for (i = 0; devc->channels[i].name; i++) {
                sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,