summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-06-09 18:55:16 +0800
committerChromeBot <chrome-bot@google.com>2013-06-09 21:33:17 -0700
commit8bed9853d7722676e49f28e36c170166dc36c8c5 (patch)
tree71d8e6584ba4c1274e198e96ff329e0377f82000
parent149a8457aa1796ddbb609396d28d83c1004c8846 (diff)
downloadchrome-ec-8bed9853d7722676e49f28e36c170166dc36c8c5.tar.gz
Bug fix of queue empty slot calculation
Current implementation of queue_has_space doesn't handle the case where queue tail has wrapped around the end. This CL fixes the bug. BUG=None TEST=Pass the test in the following CL. BRANCH=link Change-Id: I774f388081af50f0e930a6cbc3a723da1c8283b0 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/58031 Reviewed-by: Yung-Chieh Lo <yjlou@chromium.org>
-rw-r--r--common/queue.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/common/queue.c b/common/queue.c
index 8018e4c0b0..46ea749979 100644
--- a/common/queue.c
+++ b/common/queue.c
@@ -19,8 +19,12 @@ int queue_is_empty(const struct queue *q)
int queue_has_space(const struct queue *q, int unit_count)
{
- return (q->tail + unit_count * q->unit_bytes) <=
- (q->head + q->buf_bytes - q->unit_bytes);
+ if (q->tail >= q->head)
+ return (q->tail + unit_count * q->unit_bytes) <=
+ (q->head + q->buf_bytes - q->unit_bytes);
+ else
+ return (q->tail + unit_count * q->unit_bytes) <=
+ (q->head - q->unit_bytes);
}
void queue_add_units(struct queue *q, const void *src, int unit_count)