]> sigrok.org Git - libsigrok.git/blobdiff - src/lcr/es51919.c
Fix the channel indexes of the es51919 driver.
[libsigrok.git] / src / lcr / es51919.c
index 0c9054a8670467c6e8476fa9fd0caa1e0b85bc36..59dc194c5f4d795db1e6379994746f1a92d852b5 100644 (file)
@@ -41,11 +41,7 @@ static struct dev_buffer *dev_buffer_new(size_t size)
 {
        struct dev_buffer *dbuf;
 
-       if (!(dbuf = g_try_malloc(sizeof(struct dev_buffer) + size))) {
-               sr_err("Dev buffer malloc failed (size=%zu).", size);
-               return NULL;
-       }
-
+       dbuf = g_malloc0(sizeof(struct dev_buffer) + size);
        dbuf->size = size;
        dbuf->len = 0;
        dbuf->offset = 0;
@@ -779,11 +775,11 @@ static int receive_data(int fd, int revents, void *cb_data)
        return TRUE;
 }
 
-static int add_channel(struct sr_dev_inst *sdi, const char *name)
+static int add_channel(struct sr_dev_inst *sdi, int idx, const char *name)
 {
        struct sr_channel *ch;
 
-       ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, name);
+       ch = sr_channel_new(idx, SR_CHANNEL_ANALOG, TRUE, name);
        sdi->channels = g_slist_append(sdi->channels, ch);
 
        return SR_OK;
@@ -799,7 +795,7 @@ static int setup_channels(struct sr_dev_inst *sdi)
        ret = SR_ERR_BUG;
 
        for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
-               ret = add_channel(sdi, channel_names[i]);
+               ret = add_channel(sdi, i, channel_names[i]);
                if (ret != SR_OK)
                        break;
        }
@@ -846,13 +842,9 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
        sdi->vendor = g_strdup(vendor);
        sdi->model = g_strdup(model);
        devc = g_malloc0(sizeof(struct dev_context));
-
-       if (!(devc->buf = dev_buffer_new(PACKET_SIZE * 8)))
-               goto scan_cleanup;
-
+       devc->buf = dev_buffer_new(PACKET_SIZE * 8);
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
-
        sdi->priv = devc;
 
        if (setup_channels(sdi) != SR_OK)