From f15216344cca5ed7ddc12fc38116ae1a3aa6e4b4 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Tue, 28 Jun 2016 15:13:21 -0700 Subject: npcx: shi: Use worst-case logic for applying 256B bypass SHI_OBUF_VALID_OFFSET may wrap on buffer full, leaving us with an incorrect tally of bytes transmitted. Always assume the worst case, that SHI_OBUF_VALID_OFFSET is at maximum, when deciding to apply 256B bypass. BUG=chrome-os-partner:54566 BRANCH=None TEST=Manual on gru. Verify 'flashrom -p ec -r read.bin' does not produce CRC errors. Signed-off-by: Shawn Nematbakhsh Change-Id: I7c0ccc1b555838854584a3be8ced50057eaea961 Reviewed-on: https://chromium-review.googlesource.com/356771 Commit-Ready: Shawn N Tested-by: Shelley Chen Tested-by: Shawn N Reviewed-by: Randall Spangler Reviewed-by: Mulin Chao --- chip/npcx/shi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chip/npcx/shi.c b/chip/npcx/shi.c index a843612f04..482d0b74b8 100644 --- a/chip/npcx/shi.c +++ b/chip/npcx/shi.c @@ -410,14 +410,13 @@ static void shi_write_first_pkg_outbuf(uint16_t szbytes) uint16_t i; uint16_t offset, size; - offset = SHI_OBUF_VALID_OFFSET; - #ifdef NPCX_SHI_BYPASS_OVER_256B /* * If response package is across 256 bytes boundary, * bypass needs to extend PROCESSING bytes after reaching the boundary. */ - if (shi_params.bytes_in_256b + offset + szbytes > SHI_BYPASS_BOUNDARY) { + if (shi_params.bytes_in_256b + SHI_OBUF_FULL_SIZE + szbytes + > SHI_BYPASS_BOUNDARY) { state = SHI_STATE_WAIT_ALIGNMENT; /* Set pointer of output buffer to the start address */ shi_params.tx_buf = SHI_OBUF_START_ADDR; @@ -426,6 +425,7 @@ static void shi_write_first_pkg_outbuf(uint16_t szbytes) } #endif + offset = SHI_OBUF_VALID_OFFSET; shi_params.tx_buf = SHI_OBUF_START_ADDR + offset; /* Fill half output buffer */ size = MIN(SHI_OBUF_HALF_SIZE - (offset % SHI_OBUF_HALF_SIZE), -- cgit v1.2.1