sysclk-lwla: Cut down on size_t overuse

Do not use size_t for values whose width is defined by the device,
not the host. Also don't use size_t for simple indices with known
small range, unless type compatibility considerations apply.
This commit is contained in:
Daniel Elstner 2015-11-27 14:32:28 +01:00
parent 43af7604d0
commit 7ed808179f
5 changed files with 28 additions and 27 deletions

View File

@ -372,7 +372,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
const struct sr_channel_group *cg)
{
struct dev_context *devc;
size_t idx;
unsigned int idx;
(void)cg;

View File

@ -48,7 +48,8 @@ struct sr_usb_dev_inst;
#define LWLA_WORD_3(val) GUINT16_TO_LE(((val) >> 32) & 0xFFFF)
/* Maximum number of 16-bit words sent at a time during acquisition.
* Used for allocating the libusb transfer buffer.
* Used for allocating the libusb transfer buffer. Keep this even so that
* subsequent members are always 32-bit aligned.
*/
#define MAX_ACQ_SEND_LEN16 64 /* 43 for capture setup plus stuffing */
@ -124,13 +125,13 @@ struct acquisition_state {
struct libusb_transfer *xfer_in; /* USB in transfer record */
struct libusb_transfer *xfer_out; /* USB out transfer record */
size_t mem_addr_fill; /* capture memory fill level */
size_t mem_addr_done; /* position up to which data was received */
size_t mem_addr_next; /* start address for next async read */
size_t mem_addr_stop; /* end of memory range to be read */
size_t in_index; /* position in read transfer buffer */
size_t out_index; /* position in logic packet buffer */
enum rle_state rle; /* RLE decoding state */
unsigned int mem_addr_fill; /* capture memory fill level */
unsigned int mem_addr_done; /* next address to be processed */
unsigned int mem_addr_next; /* start address for next async read */
unsigned int mem_addr_stop; /* end of memory range to be read */
unsigned int in_index; /* position in read transfer buffer */
unsigned int out_index; /* position in logic packet buffer */
enum rle_state rle; /* RLE decoding state */
gboolean rle_enabled; /* capturing in timing-state mode */
gboolean clock_boost; /* switch to faster clock during capture */

View File

@ -102,9 +102,9 @@ static const char bitstream_map[][32] = {
static void read_response(struct acquisition_state *acq)
{
uint32_t *in_p, *out_p;
size_t words_left, num_words;
size_t max_samples, run_samples;
size_t i;
unsigned int words_left, num_words;
unsigned int max_samples, run_samples;
unsigned int i;
words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop)
- acq->mem_addr_done;
@ -142,9 +142,9 @@ static void read_response_rle(struct acquisition_state *acq)
{
uint32_t *in_p;
uint16_t *out_p;
size_t words_left;
size_t max_samples, run_samples;
size_t wi, ri;
unsigned int words_left;
unsigned int max_samples, run_samples;
unsigned int wi, ri;
uint32_t word;
uint16_t sample;
@ -159,11 +159,11 @@ static void read_response_rle(struct acquisition_state *acq)
run_samples = MIN(max_samples, acq->run_len);
/* Expand run-length samples into session packet. */
sample = acq->sample;
sample = GUINT16_TO_LE(acq->sample);
out_p = &((uint16_t *)acq->out_packet)[acq->out_index];
for (ri = 0; ri < run_samples; ri++)
out_p[ri] = GUINT16_TO_LE(sample);
out_p[ri] = sample;
acq->run_len -= run_samples;
acq->out_index += run_samples;
@ -285,7 +285,7 @@ static int prepare_request(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct acquisition_state *acq;
size_t count;
unsigned int count;
devc = sdi->priv;
acq = devc->acquisition;

View File

@ -170,7 +170,7 @@ static void queue_long_regval(struct acquisition_state *acq,
/* Helper to fill in the long register bulk write command.
*/
static inline void bulk_long_set(struct acquisition_state *acq,
size_t idx, uint64_t value)
unsigned int idx, uint64_t value)
{
acq->xfer_buf_out[4 * idx + 3] = LWLA_WORD_0(value);
acq->xfer_buf_out[4 * idx + 4] = LWLA_WORD_1(value);
@ -181,7 +181,7 @@ static inline void bulk_long_set(struct acquisition_state *acq,
/* Helper for dissecting the response to a long register bulk read.
*/
static inline uint64_t bulk_long_get(const struct acquisition_state *acq,
size_t idx)
unsigned int idx)
{
uint64_t low, high;
@ -200,9 +200,9 @@ static void read_response(struct acquisition_state *acq)
uint64_t sample, high_nibbles, word;
uint32_t *slice;
uint8_t *out_p;
size_t words_left;
size_t max_samples, run_samples;
size_t wi, ri, si;
unsigned int words_left;
unsigned int max_samples, run_samples;
unsigned int wi, ri, si;
/* Number of 36-bit words remaining in the transfer buffer. */
words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop)
@ -396,7 +396,7 @@ static int prepare_request(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct acquisition_state *acq;
size_t count;
unsigned int count;
devc = sdi->priv;
acq = devc->acquisition;

View File

@ -145,7 +145,7 @@ static void handle_status_response(const struct sr_dev_inst *sdi)
}
devc->state = STATE_STATUS_WAIT;
sr_spew("Captured %zu words, %" PRIu64 " ms, status 0x%02X.",
sr_spew("Captured %u words, %" PRIu64 " ms, status 0x%02X.",
acq->mem_addr_fill, acq->duration_now, acq->status);
if ((~old_status & acq->status & STATUS_TRIGGERED) != 0)
@ -189,7 +189,7 @@ static void handle_length_response(const struct sr_dev_inst *sdi)
submit_request(sdi, STATE_READ_FINISH);
return;
}
sr_dbg("%zu words in capture buffer.",
sr_dbg("%u words in capture buffer.",
acq->mem_addr_stop - acq->mem_addr_next);
submit_request(sdi, STATE_READ_PREPARE);
@ -203,7 +203,7 @@ static void handle_read_response(const struct sr_dev_inst *sdi)
struct acquisition_state *acq;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
size_t end_addr;
unsigned int end_addr;
devc = sdi->priv;
acq = devc->acquisition;