From 072d333f100f29b696e8b6be14babfae063bfcbc Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Mon, 22 Aug 2016 14:49:59 -0700 Subject: npcx: shi: Properly disable interrupts throughout sending of HC response Expand interrupt disable to include checking of our SHI state in case preemption occurs immediately afterward. BUG=chrome-os-partner:55795 BRANCH=None TEST=Manual on kevin, verify no errors through 700+ sysjumps. Signed-off-by: Shawn Nematbakhsh Change-Id: Icb8a5bdd03dbf87f6a25b4175f73c932d48db726 Reviewed-on: https://chromium-review.googlesource.com/374021 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Aseda Aboagye Reviewed-by: Mulin Chao --- chip/npcx/shi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/chip/npcx/shi.c b/chip/npcx/shi.c index 6cf030cf7c..76118abaa7 100644 --- a/chip/npcx/shi.c +++ b/chip/npcx/shi.c @@ -195,14 +195,15 @@ static uint8_t shi_read_buf_pointer(void); */ static void shi_send_response_packet(struct host_packet *pkt) { + /* + * Disable interrupts. This routine is not called from interrupt + * context and buffer underrun will likely occur if it is + * preempted after writing its initial reply byte. Also, we must be + * sure our state doesn't unexpectedly change, in case we're expected + * to take RESP_NOT_RDY actions. + */ + interrupt_disable(); if (state == SHI_STATE_PROCESSING) { - /* - * Disable interrupts. This routine is not called from interrupt - * context and buffer underrun will likely occur if it is - * preempted after writing its initial reply byte. - */ - interrupt_disable(); - /* Append our past-end byte, which we reserved space for. */ ((uint8_t *) pkt->response)[pkt->response_size + 0] = EC_SPI_PAST_END; @@ -226,8 +227,6 @@ static void shi_send_response_packet(struct host_packet *pkt) #ifdef NPCX_SHI_BYPASS_OVER_256B } #endif - - interrupt_enable(); } /* * If we're not processing, then the AP has already terminated the @@ -239,6 +238,7 @@ static void shi_send_response_packet(struct host_packet *pkt) DEBUG_CPRINTF("END\n"); } else DEBUG_CPRINTS("Unexpected state %d in response handler", state); + interrupt_enable(); } void shi_handle_host_package(void) -- cgit v1.2.1