]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-dso/api.c
Some more g_try_*alloc() fixes.
[libsigrok.git] / src / hardware / hantek-dso / api.c
index d2eebfbe55754c74571d7f46313ee41d4846d9cd..2b039ed22b60e32e499141fbb45fdf29e573a3ff 100644 (file)
@@ -69,17 +69,16 @@ static const uint32_t devopts_cg[] = {
 
 static const char *channel_names[] = {
        "CH1", "CH2",
-       NULL,
 };
 
 static const uint64_t buffersizes_32k[] = {
-       10240, 32768,
+       (10 * 1024), (32 * 1024),
 };
 static const uint64_t buffersizes_512k[] = {
-       10240, 524288,
+       (10 * 1024), (512 * 1024),
 };
 static const uint64_t buffersizes_14k[] = {
-       10240, 14336,
+       (10 * 1024), (14 * 1024),
 };
 
 static const struct dso_profile dev_profiles[] = {
@@ -181,7 +180,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
         * Add only the real channels -- EXT isn't a source of data, only
         * a trigger source internal to the device.
         */
-       for (i = 0; channel_names[i]; i++) {
+       for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
                ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
                cg = g_malloc0(sizeof(struct sr_channel_group));
                cg->name = g_strdup(channel_names[i]);
@@ -490,7 +489,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                        ch_idx = 1;
                else
                        return SR_ERR_ARG;
-               switch(key) {
+               switch (key) {
                case SR_CONF_FILTER:
                        *data = g_variant_new_boolean(devc->filter[ch_idx]);
                        break;
@@ -649,7 +648,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                return SR_ERR_ARG;
 
        if (!cg) {
-       switch (key) {
+               switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                        devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
@@ -683,7 +682,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                        return SR_ERR_NA;
                }
        } else {
-       switch (key) {
+               switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                        devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
@@ -828,8 +827,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
                }
        } else {
                /* Already past the trigger point, just send it all out. */
-               send_chunk(sdi, transfer->buffer,
-                               num_samples);
+               send_chunk(sdi, transfer->buffer, num_samples);
        }
 
        devc->samp_received += num_samples;
@@ -940,8 +938,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                devc->trigger_offset = trigger_offset;
 
                num_channels = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1;
-               /* TODO: Check malloc return value. */
-               devc->framebuf = g_try_malloc(devc->framesize * num_channels * 2);
+               devc->framebuf = g_malloc(devc->framesize * num_channels * 2);
                devc->samp_buffered = devc->samp_received = 0;
 
                /* Tell the scope to send us the first frame. */