]> sigrok.org Git - libsigrok.git/commitdiff
sr: cleanup callback: Return int.
authorUwe Hermann <redacted>
Sun, 12 Feb 2012 19:52:42 +0000 (20:52 +0100)
committerUwe Hermann <redacted>
Mon, 13 Feb 2012 18:49:01 +0000 (19:49 +0100)
hardware/alsa/alsa.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/chronovu-la8.c
hardware/demo/demo.c
hardware/link-mso19/link-mso19.c
hardware/openbench-logic-sniffer/ols.c
hardware/saleae-logic/saleae-logic.c
hardware/zeroplus-logic-cube/zeroplus.c
session_driver.c
sigrok.h

index e5fad8f56940a440b87f4d87fbd5a2591c6ec399..3d3067ce664804c7806e5f73032061c337d6e24b 100644 (file)
@@ -150,15 +150,19 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        struct sr_device_instance *sdi;
 
-       if (!(sdi = sr_get_device_instance(device_instances, 0)))
-               return;
+       if (!(sdi = sr_get_device_instance(device_instances, 0))) {
+               sr_err("alsa: %s: sdi was NULL", __func__);
+               return SR_ERR_BUG;
+       }
 
        g_free(sdi->priv);
        sr_device_instance_free(sdi);
+
+       return SR_OK;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index 5ed014079887d2f301d5d593443814a90bf416fe..02342aad7926010a02617eea8b1dcb543cfd008a 100644 (file)
@@ -721,20 +721,27 @@ 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;
+       int ret = SR_OK;
 
        /* Properly close all devices. */
        for (l = device_instances; l; l = l->next) {
-               sdi = l->data;
-               if (sdi->priv != NULL)
-                       g_free(sdi->priv);
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("asix: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               g_free(sdi->priv);
                sr_device_instance_free(sdi);
        }
        g_slist_free(device_instances);
        device_instances = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index 23ac8c793a9bdd44e0d66e44526c17f562a459ac..63d637ad81edbc08137c3b995043e1417118ed53 100644 (file)
@@ -679,17 +679,20 @@ 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;
+       int ret = SR_OK;
 
        sr_spew("la8: entering %s", __func__);
 
        /* Properly close all devices. */
        for (l = device_instances; l; l = l->next) {
-               if ((sdi = l->data) == NULL) {
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
                        sr_err("la8: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
                        continue;
                }
 #if 0
@@ -707,6 +710,8 @@ static void hw_cleanup(void)
        }
        g_slist_free(device_instances); /* Returns void. */
        device_instances = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index 5e0d44cffea379f5590104d3b51e6d06338e12ce..d302ee1e1002dc0476a6482e1341396e9448f91c 100644 (file)
@@ -174,9 +174,10 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        /* Nothing needed so far. */
+       return SR_OK;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index b3a5667f62de019265256e79957ebc7cc86d5785..0a8a073bea912153da24053d43960e4a294a2c56 100644 (file)
@@ -518,25 +518,30 @@ ret:
        return devcnt;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
        struct sr_device_instance *sdi;
+       int ret = SR_OK;
 
        /* Properly close all devices. */
        for (l = device_instances; l; l = l->next) {
-               sdi = l->data;
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("mso19: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
                if (sdi->serial->fd != -1)
                        serial_close(sdi->serial->fd);
-               if (sdi->priv != NULL)
-               {
-                       g_free(sdi->priv);
-                       sdi->priv = NULL;
-               }
+               g_free(sdi->priv);
+               sdi->priv = NULL;
                sr_device_instance_free(sdi);
        }
        g_slist_free(device_instances);
        device_instances = NULL;
+
+       return SR_OK;
 }
 
 static int hw_opendev(int device_index)
index 930d008557f9101203446104fe35648e9f5d8861..264b5658ba84f8d0a3bb5ae13344dd7a22569666 100644 (file)
@@ -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)
index 14477496e12d546a1fd7ad40118461ed2429e6db..98b9aad134c8f1832ddd0e44d0e6e733bf896181 100644 (file)
@@ -460,16 +460,28 @@ 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 fx2_device *fx2;
+       int ret = SR_OK;
 
        /* Properly close and free all devices. */
        for (l = device_instances; l; l = l->next) {
-               sdi = l->data;
-               fx2 = sdi->priv;
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("fx2: %s: sdi was NULL, continuing", __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
+               if (!(fx2 = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("fx2: %s: sdi->priv was NULL, continuing",
+                              __func__);
+                       ret = SR_ERR_BUG;
+                       continue;
+               }
                close_device(sdi);
                sr_usb_device_instance_free(fx2->usb);
                sr_device_instance_free(sdi);
@@ -481,6 +493,8 @@ static void hw_cleanup(void)
        if (usb_context)
                libusb_exit(usb_context);
        usb_context = NULL;
+
+       return ret;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index 883f5b49be5ebbda3acb02f0b43757191ab44c48..02ba89d719866242c6216c21fe26b20982c8deae 100644 (file)
@@ -485,10 +485,12 @@ static int hw_closedev(int device_index)
        return SR_OK;
 }
 
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
 
+       /* TODO: Error handling. */
+
        /* Properly close all devices... */
        for (l = device_instances; l; l = l->next)
                close_device((struct sr_device_instance *)l->data);
@@ -502,6 +504,8 @@ static void hw_cleanup(void)
        if (usb_context)
                libusb_exit(usb_context);
        usb_context = NULL;
+
+       return SR_OK;
 }
 
 static void *hw_get_device_info(int device_index, int device_info_id)
index f1c01918222e6827d1f14bd7529d5a5f4be9551b..99e4ad573590ae37f4a8b6fd7ea482a46761372a 100644 (file)
@@ -138,7 +138,7 @@ static int feed_chunk(int fd, int revents, void *session_data)
 }
 
 /* driver callbacks */
-static void hw_cleanup(void);
+static int hw_cleanup(void);
 
 /**
  * TODO.
@@ -149,7 +149,6 @@ static void hw_cleanup(void);
  */
 static int hw_init(const char *deviceinfo)
 {
-
        sessionfile = g_strdup(deviceinfo);
 
        return 0;
@@ -159,10 +158,12 @@ static int hw_init(const char *deviceinfo)
  * TODO.
  *
  */
-static void hw_cleanup(void)
+static int hw_cleanup(void)
 {
        GSList *l;
 
+       /* TODO: Error handling. */
+
        for (l = device_instances; l; l = l->next)
                sr_device_instance_free(l->data);
 
@@ -172,6 +173,8 @@ static void hw_cleanup(void)
        sr_session_source_remove(-1);
 
        g_free(sessionfile);
+
+       return SR_OK;
 }
 
 static int hw_opendev(int device_index)
index bb16a63dfcfe3525b567e78fc16f2ffe2378fbfe..e08b2aed6a1018f8947383895853daa53f9419e5 100644 (file)
--- a/sigrok.h
+++ b/sigrok.h
@@ -344,7 +344,7 @@ struct sr_device_plugin {
        char *longname;
        int api_version;
        int (*init) (const char *deviceinfo);
-       void (*cleanup) (void);
+       int (*cleanup) (void);
 
        /* Device-specific */
        int (*opendev) (int device_index);