]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/gmc-mh-1x-2x/api.c
Consistently use g_malloc0() for allocating devc.
[libsigrok.git] / src / hardware / gmc-mh-1x-2x / api.c
index a67fb0a8f9d2fb57493b20ec0743cc527eb9ebba..02eb6d6e18e7bcb21778f9879336e71ea42bc00e 100644 (file)
@@ -223,20 +223,17 @@ static GSList *scan_1x_2x_rs232(GSList *options)
 
        if (model != METRAHIT_NONE) {
                sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model));
-               if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, VENDOR_GMC,
-                               gmc_model_str(model), NULL)))
-                       return NULL;
-               if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
-                       sr_err("Device context malloc failed.");
-                       return NULL;
-               }
+               sdi = g_malloc0(sizeof(struct sr_dev_inst));
+               sdi->status = SR_ST_INACTIVE;
+               sdi->vendor = g_strdup(VENDOR_GMC);
+               sdi->model = g_strdup(gmc_model_str(model));
+               devc = g_malloc0(sizeof(struct dev_context));
                devc->model = model;
                devc->limit_samples = 0;
                devc->limit_msec = 0;
                devc->num_samples = 0;
                devc->elapsed_msec = g_timer_new();
                devc->settings_ok = FALSE;
-
                sdi->conn = serial;
                sdi->priv = devc;
                sdi->driver = &gmc_mh_1x_2x_rs232_driver_info;
@@ -298,14 +295,11 @@ static GSList *scan_2x_bd232(GSList *options)
        if (serial_open(serial, SERIAL_RDWR) != SR_OK)
                goto exit_err;
 
-       if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
-               sr_err("Device context malloc failed.");
-               goto exit_err;
-       }
-
-       if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL)))
-               goto exit_err;
+       devc = g_malloc0(sizeof(struct dev_context));
 
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_INACTIVE;
+       sdi->vendor = g_strdup(VENDOR_GMC);
        sdi->priv = devc;
 
        /* Send message 03 "Query multimeter version and status" */
@@ -349,13 +343,11 @@ static GSList *scan_2x_bd232(GSList *options)
                        drvc->instances = g_slist_append(drvc->instances, sdi);
                        devices = g_slist_append(devices, sdi);
 
-                       if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
-                               sr_err("Device context malloc failed.");
-                               goto exit_err;
-                       }
+                       devc = g_malloc0(sizeof(struct dev_context));
 
-                       if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL)))
-                               goto exit_err;
+                       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+                       sdi->status = SR_ST_INACTIVE;
+                       sdi->vendor = g_strdup(VENDOR_GMC);
                }
        };