From: Uwe Hermann Date: Sun, 12 Feb 2012 19:52:42 +0000 (+0100) Subject: sr: cleanup callback: Return int. X-Git-Tag: libsigrok-0.1.0~126 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=57ab7d9f925c0f93ec711c4e6914881e5ff5dfd9;p=libsigrok.git sr: cleanup callback: Return int. --- diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index e5fad8f5..3d3067ce 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -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) diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 5ed01407..02342aad 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -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) diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 23ac8c79..63d637ad 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -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) diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 5e0d44cf..d302ee1e 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -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) diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index b3a5667f..0a8a073b 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -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) diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index 930d0085..264b5658 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -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) diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index 14477496..98b9aad1 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -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) diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 883f5b49..02ba89d7 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -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) diff --git a/session_driver.c b/session_driver.c index f1c01918..99e4ad57 100644 --- a/session_driver.c +++ b/session_driver.c @@ -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) diff --git a/sigrok.h b/sigrok.h index bb16a63d..e08b2aed 100644 --- 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);