]> sigrok.org Git - libsigrok.git/blobdiff - hardware/link-mso19/link-mso19.c
libsigrok: Rename open/close to opendev/closedev.
[libsigrok.git] / hardware / link-mso19 / link-mso19.c
index 18e28cff514fed93263b461a3456e34f7b6ccc69..d37ba02077a06cced83879fef655a61a667a9dc3 100644 (file)
@@ -86,12 +86,16 @@ static int mso_send_control_message(struct sr_device_instance *sdi,
        int i, w, ret, s = n * 2 + sizeof(mso_head) + sizeof(mso_foot);
        char *p, *buf;
 
+       ret = SR_ERR;
+
        if (fd < 0)
                goto ret;
 
-       buf = malloc(s);
-       if (!buf)
+       if (!(buf = g_try_malloc(s))) {
+               sr_err("mso19: %s: buf malloc failed", __func__);
+               ret = SR_ERR_MALLOC;
                goto ret;
+       }
 
        p = buf;
        memcpy(p, mso_head, sizeof(mso_head));
@@ -114,7 +118,7 @@ static int mso_send_control_message(struct sr_device_instance *sdi,
        }
        ret = SR_OK;
 free:
-       free(buf);
+       g_free(buf);
 ret:
        return ret;
 }
@@ -386,7 +390,7 @@ static int hw_init(const char *deviceinfo)
         */
        udev = udev_new();
        if (!udev) {
-               g_warning("Failed to initialize udev.");
+               sr_warn("Failed to initialize udev.");
                goto ret;
        }
        enumerate = udev_enumerate_new(udev);
@@ -406,8 +410,8 @@ static int hw_init(const char *deviceinfo)
                parent = udev_device_get_parent_with_subsystem_devtype(
                                dev, "usb", "usb_device");
                if (!parent) {
-                       g_warning("Unable to find parent usb device for %s",
-                                       sysname);
+                       sr_warn("Unable to find parent usb device for %s",
+                               sysname);
                        continue;
                }
 
@@ -425,7 +429,7 @@ static int hw_init(const char *deviceinfo)
                s = strcspn(iProduct, " ");
                if (s > sizeof(product) ||
                                strlen(iProduct) - s > sizeof(manufacturer)) {
-                       g_warning("Could not parse iProduct: %s", iProduct);
+                       sr_warn("Could not parse iProduct: %s", iProduct);
                        continue;
                }
                strncpy(product, iProduct, s);
@@ -433,13 +437,13 @@ static int hw_init(const char *deviceinfo)
                strcpy(manufacturer, iProduct + s);
                sprintf(hwrev, "r%d", mso->hwrev);
 
-               mso = malloc(sizeof(struct mso));
-               if (!mso)
-                       continue;
-               memset(mso, 0, sizeof(struct mso));
+               if (!(mso = g_try_malloc0(sizeof(struct mso)))) {
+                       sr_err("mso19: %s: mso malloc failed", __func__);
+                       continue; /* TODO: Errors handled correctly? */
+               }
 
                if (mso_parse_serial(iSerial, iProduct, mso) != SR_OK) {
-                       g_warning("Invalid iSerial: %s", iSerial);
+                       sr_warn("Invalid iSerial: %s", iSerial);
                        goto err_free_mso;
                }
                /* hardware initial state */
@@ -448,8 +452,8 @@ static int hw_init(const char *deviceinfo)
                sdi = sr_device_instance_new(devcnt, SR_ST_INITIALIZING,
                        manufacturer, product, hwrev);
                if (!sdi) {
-                       g_warning("Unable to create device instance for %s",
-                                       sysname);
+                       sr_warn("Unable to create device instance for %s",
+                               sysname);
                        goto err_free_mso;
                }
 
@@ -518,14 +522,14 @@ static int hw_opendev(int device_index)
        /* FIXME: discard serial buffer */
 
        mso_check_trigger(sdi, &mso->trigger_state);
-//     g_warning("trigger state: %c", mso->trigger_state);
+//     sr_warn("trigger state: %c", mso->trigger_state);
 
        ret = mso_reset_adc(sdi);
        if (ret != SR_OK)
                return ret;
 
        mso_check_trigger(sdi, &mso->trigger_state);
-//     g_warning("trigger state: %c", mso->trigger_state);
+//     sr_warn("trigger state: %c", mso->trigger_state);
 
 //     ret = mso_reset_fsm(sdi);
 //     if (ret != SR_OK)
@@ -775,8 +779,8 @@ struct sr_device_plugin link_mso19_plugin_info = {
        .api_version = 1,
        .init = hw_init,
        .cleanup = hw_cleanup,
-       .open = hw_opendev,
-       .close = hw_closedev,
+       .opendev = hw_opendev,
+       .closedev = hw_closedev,
        .get_device_info = hw_get_device_info,
        .get_status = hw_get_status,
        .get_capabilities = hw_get_capabilities,