libbladeRF: [WIP] Cleanup of backend open and probe

This commit is contained in:
Jon Szymaniak 2013-08-11 15:52:08 -04:00
commit 77f8aadb25
4 changed files with 27 additions and 21 deletions

View file

@ -31,11 +31,10 @@ static const struct bladerf_fn * backend_fns[] = {
int open_with_any_backend(struct bladerf **device,
struct bladerf_devinfo *info)
{
int status = 0;
int status = BLADERF_ERR_NODEV;
const struct bladerf_fn **fn_tbl;
struct bladerf *ret = NULL;
for (fn_tbl = &backend_fns[0]; *fn_tbl != NULL && ret == NULL; fn_tbl++) {
for (fn_tbl = &backend_fns[0]; *fn_tbl != NULL && status != 0; fn_tbl++) {
assert((*fn_tbl)->open);
status = (*fn_tbl)->open(device, info);
}

View file

@ -597,7 +597,10 @@ static int lusb_get_device_speed(struct bladerf *dev, int *device_speed)
static int access_peripheral(struct bladerf_lusb *lusb, int per, int dir,
struct uart_cmd *cmd)
{
uint8_t buf[16];
uint8_t buf[16] = { 0 }; /* Zeroing out to avoid some valgrind noise
* on the reserved items that aren't currently
* used (i.e., bytes 4-15 */
int status, libusb_status, transferred;
/* Populate the buffer for transfer */

View file

@ -510,7 +510,11 @@ static int linux_open( struct bladerf **device, struct bladerf_devinfo *info)
} else {
status = linux_probe(&list);
if (status < 0) {
dbg_printf("Probe failed: %s\n", bladerf_strerror(status));
if (status == BLADERF_ERR_NODEV) {
dbg_printf("No devices available on the Linux driver backend.\n");
} else {
dbg_printf("Probe failed: %s\n", bladerf_strerror(status));
}
} else {
for (i = 0; i < list.num_elt && !ret; i++) {
if (bladerf_devinfo_matches(&list.elt[i], info)) {

View file

@ -55,31 +55,31 @@ static void init_stats(struct bladerf_stats *stats)
int bladerf_open_with_devinfo(struct bladerf **device,
struct bladerf_devinfo *devinfo)
{
struct bladerf *opened_device;
int status;
struct bladerf *ret;
*device = NULL;
status = backend_open(device, devinfo);
status = backend_open(&ret, devinfo);
if (!status) {
/* Catch bugs from backends returning status = 0, but a NULL device */
assert(*device);
opened_device = *device;
/* We got a device */
if (ret) {
bladerf_set_error(&ret->error, ETYPE_LIBBLADERF, 0);
init_stats(&ret->stats);
bladerf_set_error(&opened_device->error, ETYPE_LIBBLADERF, 0);
init_stats(&opened_device->stats);
ret->last_tx_sample_rate = 0;
ret->last_rx_sample_rate = 0;
opened_device->last_tx_sample_rate = 0;
opened_device->last_rx_sample_rate = 0;
status = ret->fn->get_device_speed(ret, &ret->speed);
if (status < 0) {
ret->fn->close(ret);
ret = NULL;
} else {
*device = ret;
}
} else {
status = BLADERF_ERR_NODEV;
status = opened_device->fn->get_device_speed(opened_device,
&opened_device->speed);
if (status < 0) {
opened_device->fn->close((*device));
*device = NULL;
}
}