]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/zeroplus.c
Return SR_ERR_MALLOC upon allocation errors.
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
index 94ce37e18879cd54113c3b18d7142b03dcdf51bf..f1b6431b9f8c93a8e7f750305928d99700d73e7a 100644 (file)
@@ -24,7 +24,6 @@
 #include <inttypes.h>
 #include <glib.h>
 #include <libusb.h>
-#include "config.h"
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 #include "analyzer.h"
@@ -72,7 +71,6 @@ static model_t zeroplus_models[] = {
 static const int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
        SR_HWCAP_SAMPLERATE,
-       SR_HWCAP_PROBECONFIG,
        SR_HWCAP_CAPTURE_RATIO,
 
        /* These are really implemented in the driver, not the hardware. */
@@ -148,11 +146,6 @@ static const struct sr_samplerates samplerates = {
        supported_samplerates,
 };
 
-/* Private driver context. */
-struct drv_context {
-       GSList *instances;
-};
-
 /* Private, per-device-instance driver context. */
 struct dev_context {
        uint64_t cur_samplerate;
@@ -186,7 +179,7 @@ static unsigned int get_memory_size(int type)
                return 0;
 }
 
-static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
+static int configure_probes(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        const struct sr_probe *probe;
@@ -204,7 +197,7 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
        }
 
        stage = -1;
-       for (l = probes; l; l = l->next) {
+       for (l = sdi->probes; l; l = l->next) {
                probe = (struct sr_probe *)l->data;
                if (probe->enabled == FALSE)
                        continue;
@@ -227,15 +220,22 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
        return SR_OK;
 }
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
        struct drv_context *drvc;
+       struct dev_context *devc;
 
        drvc = zdi->priv;
        for (l = drvc->instances; l; l = l->next) {
                sdi = l->data;
+               if (!(devc = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("zeroplus: %s: sdi->priv was NULL, continuing", __func__);
+                       continue;
+               }
+               sr_usb_dev_inst_free(devc->usb);
                /* Properly close all devices... */
                hw_dev_close(sdi);
                /* ...and free all their memory. */
@@ -244,6 +244,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 /*
@@ -256,7 +257,7 @@ static int hw_init(void)
 
        if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
                sr_err("zeroplus: driver context malloc failed.");
-               return SR_ERR;
+               return SR_ERR_MALLOC;
        }
        zdi->priv = drvc;
 
@@ -320,7 +321,7 @@ static GSList *hw_scan(GSList *options)
                /* Allocate memory for our private driver context. */
                if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
                        sr_err("zp: %s: devc malloc failed", __func__);
-                       return 0;
+                       return NULL;
                }
                sdi->priv = devc;
                devc->num_channels = prof->channels;
@@ -348,6 +349,15 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = zdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -564,8 +574,6 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
        switch (hwcap) {
        case SR_HWCAP_SAMPLERATE:
                return set_samplerate(sdi, *(const uint64_t *)value);
-       case SR_HWCAP_PROBECONFIG:
-               return configure_probes(sdi, (const GSList *)value);
        case SR_HWCAP_LIMIT_SAMPLES:
                devc->limit_samples = *(const uint64_t *)value;
                return SR_OK;
@@ -592,6 +600,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR_ARG;
        }
 
+       if (configure_probes(sdi) != SR_OK) {
+               sr_err("zp: failed to configured probes");
+               return SR_ERR;
+       }
+
        /* push configured settings to device */
        analyzer_configure(devc->usb->devhdl);
 
@@ -678,6 +691,8 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = hw_cleanup,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,