]> 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 7dcda9cfd4dcc46310df96fcbad8a3ea9130eb3f..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,7 +220,7 @@ 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;
@@ -251,6 +244,7 @@ static void clear_instances(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 /*
@@ -263,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;
 
@@ -327,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;
@@ -355,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;
@@ -571,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;
@@ -599,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);
 
@@ -685,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,