]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/ols.c
sr: cleanup callback: Return int.
[libsigrok.git] / hardware / openbench-logic-sniffer / ols.c
index 1b7970e31ed18f3ec3eff9cfbefa89642dd2a0e5..264b5658ba84f8d0a3bb5ae13344dd7a22569666 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the sigrok project.
  *
- * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -359,7 +359,7 @@ static int hw_init(const char *deviceinfo)
        final_devcnt = 0;
 
        if (deviceinfo)
-               ports = g_slist_append(NULL, strdup(deviceinfo));
+               ports = g_slist_append(NULL, g_strdup(deviceinfo));
        else
                /* No specific device given, so scan all serial ports. */
                ports = list_serial_ports();
@@ -415,10 +415,10 @@ static int hw_init(const char *deviceinfo)
                        send_shortcommand(fd, CMD_ID);
                        fds[devcnt].fd = fd;
                        fds[devcnt].events = G_IO_IN;
-                       device_names[devcnt] = strdup(l->data);
+                       device_names[devcnt] = g_strdup(l->data);
                        devcnt++;
                }
-               free(l->data);
+               g_free(l->data);
        }
 
        /* 2ms isn't enough for reliable transfer with pl2303, let's try 10 */
@@ -465,8 +465,8 @@ static int hw_init(const char *deviceinfo)
                        serial_restore_params(fds[i].fd, serial_params[i]);
                        serial_close(fds[i].fd);
                }
-               free(serial_params[i]);
-               free(device_names[i]);
+               g_free(serial_params[i]);
+               g_free(device_names[i]);
        }
 
        g_free(serial_params);
@@ -521,16 +521,29 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
        struct sr_device_instance *sdi;
        struct ols_device *ols;
+       int ret = SR_OK;
 
        /* Properly close and free all devices. */
        for (l = device_instances; l; l = l->next) {
-               sdi = l->data;
-               ols = sdi->priv;
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("ols: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               if (!(ols = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("ols: %s: sdi->priv was NULL, continuing",
+                              __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               /* TODO: Check for serial != NULL. */
                if (ols->serial->fd != -1)
                        serial_close(ols->serial->fd);
                sr_serial_device_instance_free(ols->serial);
@@ -538,6 +551,8 @@ static void hw_cleanup(void)
        }
        g_slist_free(device_instances);
        device_instances = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
@@ -614,11 +629,11 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
         * from the requested.
         */
        ols->cur_samplerate = CLOCK_RATE / (ols->cur_samplerate_divider + 1);
-       if(ols->flag_reg & FLAG_DEMUX)
+       if (ols->flag_reg & FLAG_DEMUX)
                ols->cur_samplerate *= 2;
-       if(ols->cur_samplerate != samplerate)
-               sr_warn("ols: can't match samplerate %" PRIu64 ", using %" PRIu64, 
-                       samplerate, ols->cur_samplerate);
+       if (ols->cur_samplerate != samplerate)
+               sr_err("ols: can't match samplerate %" PRIu64 ", using %"
+                      PRIu64, samplerate, ols->cur_samplerate);
 
        return SR_OK;
 }
@@ -650,7 +665,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
                if (*tmp_u64 < MIN_NUM_SAMPLES)
                        return SR_ERR;
                if (*tmp_u64 > ols->max_samples)
-                       sr_warn("ols: sample limit exceeds hw max");
+                       sr_err("ols: sample limit exceeds hw max");
                ols->limit_samples = *tmp_u64;
                sr_info("ols: sample limit %" PRIu64, ols->limit_samples);
                ret = SR_OK;
@@ -1002,7 +1017,6 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        gettimeofday(&header->starttime, NULL);
        header->samplerate = ols->cur_samplerate;
        header->num_logic_probes = NUM_PROBES;
-       header->num_analog_probes = 0;
        sr_session_bus(session_data, packet);
 
        g_free(header);
@@ -1011,7 +1025,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        return SR_OK;
 }
 
-static void hw_stop_acquisition(int device_index, gpointer session_device_id)
+static int hw_stop_acquisition(int device_index, gpointer session_device_id)
 {
        struct sr_datafeed_packet packet;
 
@@ -1020,9 +1034,11 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
 
        packet.type = SR_DF_END;
        sr_session_bus(session_device_id, &packet);
+
+       return SR_OK;
 }
 
-struct sr_device_plugin ols_plugin_info = {
+SR_PRIV struct sr_device_plugin ols_plugin_info = {
        .name = "ols",
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,