From: Uwe Hermann Date: Wed, 22 Feb 2012 18:53:27 +0000 (+0100) Subject: sr: la8: Remove some unneeded checks. X-Git-Tag: libsigrok-0.1.0~103 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=47671b0f26cc6b3e7cf16257f458eadefe623d9f;p=libsigrok.git sr: la8: Remove some unneeded checks. --- diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index fea43db8..28aea6b2 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -1,7 +1,7 @@ /* * This file is part of the sigrok project. * - * Copyright (C) 2011 Uwe Hermann + * Copyright (C) 2011-2012 Uwe Hermann * * 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 @@ -206,24 +206,17 @@ static uint8_t samplerate_to_divcount(uint64_t samplerate) /** * Write data of a certain length to the LA8's FTDI device. * - * @param ctx The struct containing private per-device-instance data. - * @param buf The buffer containing the data to write. - * @param size The number of bytes to write. + * @param ctx The struct containing private per-device-instance data. Must not + * be NULL. ctx->ftdic must not be NULL either. + * @param buf The buffer containing the data to write. Must not be NULL. + * @param size The number of bytes to write. Must be >= 0. * @return The number of bytes written, or a negative value upon errors. */ static int la8_write(struct context *ctx, uint8_t *buf, int size) { int bytes_written; - if (!ctx) { - sr_err("la8: %s: ctx was NULL", __func__); - return SR_ERR_ARG; - } - - if (!ctx->ftdic) { - sr_err("la8: %s: ctx->ftdic was NULL", __func__); - return SR_ERR_ARG; - } + /* Note: Caller checked that ctx and ctx->ftdic != NULL. */ if (!buf) { sr_err("la8: %s: buf was NULL", __func__); @@ -253,24 +246,18 @@ static int la8_write(struct context *ctx, uint8_t *buf, int size) /** * Read a certain amount of bytes from the LA8's FTDI device. * - * @param ctx The struct containing private per-device-instance data. - * @param buf The buffer where the received data will be stored. - * @param size The number of bytes to read. + * @param ctx The struct containing private per-device-instance data. Must not + * be NULL. ctx->ftdic must not be NULL either. + * @param buf The buffer where the received data will be stored. Must not + * be NULL. + * @param size The number of bytes to read. Must be >= 1. * @return The number of bytes read, or a negative value upon errors. */ static int la8_read(struct context *ctx, uint8_t *buf, int size) { int bytes_read; - if (!ctx) { - sr_err("la8: %s: ctx was NULL", __func__); - return SR_ERR_ARG; - } - - if (!ctx->ftdic) { - sr_err("la8: %s: ctx->ftdic was NULL", __func__); - return SR_ERR_ARG; - } + /* Note: Caller checked that ctx and ctx->ftdic != NULL. */ if (!buf) { sr_err("la8: %s: buf was NULL", __func__); @@ -418,6 +405,8 @@ static int configure_probes(struct context *ctx, GSList *probes) uint8_t probe_bit; char *tc; + /* Note: Caller checked that ctx != NULL. */ + ctx->trigger_pattern = 0; ctx->trigger_mask = 0; /* Default to "don't care" for all probes. */ @@ -613,15 +602,9 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { struct context *ctx; - if (!sdi) { - sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR_ARG; - } + /* Note: Caller checked that sdi and sdi->priv != NULL. */ - if (!(ctx = sdi->priv)) { - sr_err("la8: %s: sdi->priv was NULL", __func__); - return SR_ERR_ARG; - } + ctx = sdi->priv; sr_spew("la8: setting samplerate"); @@ -829,15 +812,7 @@ static int la8_read_block(struct context *ctx) int i, byte_offset, m, mi, p, index, bytes_read; time_t now; - if (!ctx) { - sr_err("la8: %s: ctx was NULL", __func__); - return SR_ERR_ARG; - } - - if (!ctx->ftdic) { - sr_err("la8: %s: ctx->ftdic was NULL", __func__); - return SR_ERR_ARG; - } + /* Note: Caller checked that ctx and ctx->ftdic != NULL. */ sr_spew("la8: %s: reading block %d", __func__, ctx->block_counter); @@ -988,6 +963,11 @@ static int receive_data(int fd, int revents, void *session_data) return FALSE; } + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); + return FALSE; + } + /* Get one block of data. */ if ((ret = la8_read_block(ctx)) < 0) { sr_err("la8: %s: la8_read_block error: %d", __func__, ret);