From: Daniel Elstner Date: Fri, 27 Nov 2015 13:32:28 +0000 (+0100) Subject: sysclk-lwla: Cut down on size_t overuse X-Git-Tag: libsigrok-0.4.0~100 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7ed808179f5542c903a476266c4b175a6f2a18a7;p=libsigrok.git 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. --- diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index be62551b..d093430d 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -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; diff --git a/src/hardware/sysclk-lwla/lwla.h b/src/hardware/sysclk-lwla/lwla.h index 7bd58864..f0f280fa 100644 --- a/src/hardware/sysclk-lwla/lwla.h +++ b/src/hardware/sysclk-lwla/lwla.h @@ -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 */ diff --git a/src/hardware/sysclk-lwla/lwla1016.c b/src/hardware/sysclk-lwla/lwla1016.c index b8031941..59557efd 100644 --- a/src/hardware/sysclk-lwla/lwla1016.c +++ b/src/hardware/sysclk-lwla/lwla1016.c @@ -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; diff --git a/src/hardware/sysclk-lwla/lwla1034.c b/src/hardware/sysclk-lwla/lwla1034.c index bc49f794..baf3d1e9 100644 --- a/src/hardware/sysclk-lwla/lwla1034.c +++ b/src/hardware/sysclk-lwla/lwla1034.c @@ -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; diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index 6d9c7c75..6c940ac2 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -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;