From: Gerhard Sittig Date: Sun, 15 Oct 2023 08:31:15 +0000 (+0200) Subject: input/protocoldata: improve use of feed queue API X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=29bd62ff51b33f2042310b3117a8035a64232cae;p=libsigrok.git input/protocoldata: improve use of feed queue API Improve feed queue related calls in the submission of capture start/end idle phases, inter-frame idle phases, and bit time quanta of generated protocol traffic. The submit-one API call accepts a repeat count which eliminates caller's loops. This also happens to eliminate a misguided yet harmless wrong use of the feed queue API. An earlier implementation assumed "data pointer, and data size" as arguments, and looped around that at the caller's. While it's "data pointer, and repeat count". Used to work because sizeof(u8) "was mistaken" as repeat count 1, so this flaw went unnoticed. Propagate errors as they are seen, an earlier implementation silently ignored them for frame payloads. --- diff --git a/src/input/protocoldata.c b/src/input/protocoldata.c index c1d516f4..148048ea 100644 --- a/src/input/protocoldata.c +++ b/src/input/protocoldata.c @@ -713,12 +713,9 @@ static int send_idle_capture(struct context *inc) if (ret != SR_OK) return ret; count *= inc->curr_opts.samples_per_bit; - while (count--) { - ret = feed_queue_logic_submit_one(inc->feed_logic, - &data, sizeof(data)); - if (ret != SR_OK) - return ret; - } + ret = feed_queue_logic_submit_one(inc->feed_logic, &data, count); + if (ret != SR_OK) + return ret; return SR_OK; } @@ -738,12 +735,9 @@ static int send_idle_interframe(struct context *inc) ret = handler->get_idle_interframe(inc, &count, &data); if (ret != SR_OK) return ret; - while (count--) { - ret = feed_queue_logic_submit_one(inc->feed_logic, - &data, sizeof(data)); - if (ret != SR_OK) - return ret; - } + ret = feed_queue_logic_submit_one(inc->feed_logic, &data, count); + if (ret != SR_OK) + return ret; return SR_OK; } @@ -754,16 +748,17 @@ static int send_frame(struct sr_input *in) struct context *inc; size_t count, index; uint8_t data; + int ret; inc = in->priv; for (index = 0; index < inc->top_frame_bits; index++) { data = inc->sample_levels[index]; count = inc->sample_widths[index]; - while (count--) { - feed_queue_logic_submit_one(inc->feed_logic, - &data, sizeof(data)); - } + ret = feed_queue_logic_submit_one(inc->feed_logic, + &data, count); + if (ret != SR_OK) + return ret; } return SR_OK;