From: Keith Packard Date: Thu, 28 Mar 2013 22:55:35 +0000 (-0700) Subject: altos: Add sanity checking to busy counts in bufio driver X-Git-Tag: altosdroid_v1.2-1~71 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=d1fe0654b45cc8f944394308cf29945b537becc4 altos: Add sanity checking to busy counts in bufio driver Make sure the busy counts don't underflow or overflow. Signed-off-by: Keith Packard --- diff --git a/src/drivers/ao_bufio.c b/src/drivers/ao_bufio.c index 9a5e801b..10b32ceb 100644 --- a/src/drivers/ao_bufio.c +++ b/src/drivers/ao_bufio.c @@ -205,10 +205,13 @@ ao_bufio_get(uint32_t block) bufio->block = 0xffffffff; bufio = NULL; } - } + } else + ao_panic(AO_PANIC_BUFIO); } if (bufio) { bufio->busy++; + if (!bufio->busy) + ao_panic(AO_PANIC_BUFIO); buf = ao_bufio_to_buf(bufio); } ao_bufio_unlock(); @@ -227,6 +230,9 @@ ao_bufio_put(uint8_t *buf, uint8_t write) ao_bufio_lock(); bufio = ao_buf_to_bufio(buf); + if (!bufio->busy) + ao_panic(AO_PANIC_BUFIO); + DBG ("idle buffer %d write %d\n", ao_bufio_to_num(bufio), write); bufio->dirty |= write; if (!--bufio->busy) {