EC: snow: keyboard: fix incorrect index calculation with empty fifo

When kb_fifo_start is 0, the index calculation yields -1 because C got
the mod (%) operation arguably wrong.  By adding KB_FIFO_DEPTH to the
index before computing the mod with respect to KB_FIFO_DEPTH, we avoid
the negative case and (obviously) produce the same result in all other
cases.

BUG=chrome-os-partner:10247
TEST=saw incorrect state from kernel log before fix: could not repro after.

Signed-off-by: Luigi Semenzato <semenzato@chromium.org>

Change-Id: I3a30c229dc9f762dd45203e842128811a24cf53f
Reviewed-on: https://gerrit.chromium.org/gerrit/24730
Tested-by: Luigi Semenzato <semenzato@google.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Ready: Luigi Semenzato <semenzato@google.com>
This commit is contained in:
Luigi Semenzato
2012-06-07 10:30:53 -07:00
committed by Gerrit
parent 153fb897ca
commit 20d730b322

View File

@@ -138,8 +138,8 @@ static int kb_fifo_remove(uint8_t *buffp)
{
if (!kb_fifo_entries) {
/* no entry remaining in FIFO : return last known state */
memcpy(buffp, kb_fifo[(kb_fifo_start - 1) % KB_FIFO_DEPTH],
KB_OUTPUTS);
int last = (kb_fifo_start + KB_FIFO_DEPTH - 1) % KB_FIFO_DEPTH;
memcpy(buffp, kb_fifo[last], KB_OUTPUTS);
/*
* Bail out without changing any FIFO indices and let the