X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fsaleae-logic%2Fsaleae-logic.c;h=98b9aad134c8f1832ddd0e44d0e6e733bf896181;hb=c532476aa7b9a4afb1f32d5b634348d3e825d6bb;hp=ab303306265155437781448c4296134c451ff4a3;hpb=d38cd6c1f6f3f23b2f659be2d189f56c7592b805;p=libsigrok.git diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index ab303306..98b9aad1 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -1,7 +1,7 @@ /* * This file is part of the sigrok project. * - * Copyright (C) 2012 Bert Vermeulen + * Copyright (C) 2010-2012 Bert Vermeulen * * 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 @@ -94,7 +94,7 @@ static libusb_context *usb_context = NULL; static int new_saleae_logic_firmware = 0; static int hw_set_configuration(int device_index, int capability, void *value); -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static int hw_stop_acquisition(int device_index, gpointer session_device_id); /** * Check the USB configuration to determine if this is a Saleae Logic. @@ -185,7 +185,7 @@ static int sl_open_device(int device_index) libusb_get_device_list(usb_context, &devlist); for (i = 0; devlist[i]; i++) { if ((err = libusb_get_device_descriptor(devlist[i], &des))) { - sr_warn("failed to get device descriptor: %d", err); + sr_err("failed to get device descriptor: %d", err); continue; } @@ -222,7 +222,7 @@ static int sl_open_device(int device_index) sdi->index, fx2->usb->bus, fx2->usb->address, USB_INTERFACE); } else { - sr_warn("failed to open device: %d", err); + sr_err("failed to open device: %d", err); } /* if we made it here, we handled the device one way or another */ @@ -331,7 +331,7 @@ static int hw_init(const char *deviceinfo) (void)deviceinfo; if (libusb_init(&usb_context) != 0) { - sr_warn("Failed to initialize USB."); + sr_err("Failed to initialize USB."); return 0; } @@ -342,7 +342,7 @@ static int hw_init(const char *deviceinfo) fx2_prof = NULL; err = libusb_get_device_descriptor(devlist[i], &des); if (err != 0) { - sr_warn("failed to get device descriptor: %d", err); + sr_err("failed to get device descriptor: %d", err); continue; } @@ -379,7 +379,7 @@ static int hw_init(const char *deviceinfo) /* Remember when the firmware on this device was updated */ g_get_current_time(&fx2->fw_updated); else - sr_warn("firmware upload failed for device %d", devcnt); + sr_err("firmware upload failed for device %d", devcnt); fx2->usb = sr_usb_device_instance_new (libusb_get_bus_number(devlist[i]), 0xff, NULL); } @@ -424,14 +424,14 @@ static int hw_opendev(int device_index) } if (err != SR_OK) { - sr_warn("unable to open device"); + sr_err("unable to open device"); return SR_ERR; } fx2 = sdi->priv; err = libusb_claim_interface(fx2->usb->devhdl, USB_INTERFACE); if (err != 0) { - sr_warn("Unable to claim interface: %d", err); + sr_err("Unable to claim interface: %d", err); return SR_ERR; } @@ -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) @@ -603,7 +617,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi, ret = libusb_bulk_transfer(fx2->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT, buf, 2, &result, 500); if (ret != 0) { - sr_warn("failed to set samplerate: %d", ret); + sr_err("failed to set samplerate: %d", ret); return SR_ERR; } fx2->cur_samplerate = samplerate; @@ -689,15 +703,14 @@ static void receive_transfer(struct libusb_transfer *transfer) /* Fire off a new request. */ if (!(new_buf = g_try_malloc(4096))) { sr_err("saleae: %s: new_buf malloc failed", __func__); - // return SR_ERR_MALLOC; - return; /* FIXME */ + return; /* TODO: SR_ERR_MALLOC */ } transfer->buffer = new_buf; transfer->length = 4096; if (libusb_submit_transfer(transfer) != 0) { /* TODO: Stop session? */ - sr_warn("eek"); + sr_err("eek"); } if (cur_buflen == 0) { @@ -841,7 +854,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data) for (i = 0; lupfd[i]; i++) sr_source_add(lupfd[i]->fd, lupfd[i]->events, 40, receive_data, NULL); - free(lupfd); + free(lupfd); /* NOT g_free()! */ packet->type = SR_DF_HEADER; packet->payload = header; @@ -857,7 +870,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data) } /* This stops acquisition on ALL devices, ignoring device_index. */ -static void hw_stop_acquisition(int device_index, gpointer session_data) +static int hw_stop_acquisition(int device_index, gpointer session_data) { struct sr_datafeed_packet packet; @@ -870,6 +883,8 @@ static void hw_stop_acquisition(int device_index, gpointer session_data) receive_transfer(NULL); /* TODO: Need to cancel and free any queued up transfers. */ + + return SR_OK; } SR_PRIV struct sr_device_plugin saleae_logic_plugin_info = {