From ce4f7ba59cd09dcb93c631797c62f3d8ebb0a4e4 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Mon, 15 Aug 2016 15:03:07 -0600 Subject: common/spi_nor.c: Don't update capacity or page_size after error If there was an error getting the capacity or page size, don't update the values with an incorrect/unknown/uninitialized value. BUG=None BRANCH=None TEST=Build all boards successfully. Change-Id: I907f14f219f721ec9e9753a38e4bf998bbc16324 Signed-off-by: Martin Roth Reviewed-on: https://chromium-review.googlesource.com/370665 Reviewed-by: David Hendricks Reviewed-by: Ewout van Bekkum --- common/spi_nor.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'common/spi_nor.c') diff --git a/common/spi_nor.c b/common/spi_nor.c index 9c0bec9523..dc69b19c3c 100644 --- a/common/spi_nor.c +++ b/common/spi_nor.c @@ -444,16 +444,17 @@ int spi_nor_init(void) spi_nor_device, table_major_rev, table_minor_rev, table_offset, &capacity); - - mutex_lock(&driver_mutex); - spi_nor_device->capacity = capacity; - spi_nor_device->page_size = page_size; - DEBUG_CPRINTS_DEVICE( - spi_nor_device, - "Updated to SFDP params: %dKiB w/ %dB pages", - spi_nor_device->capacity >> 10, - spi_nor_device->page_size); - mutex_unlock(&driver_mutex); + if (rv == EC_SUCCESS) { + mutex_lock(&driver_mutex); + spi_nor_device->capacity = capacity; + spi_nor_device->page_size = page_size; + DEBUG_CPRINTS_DEVICE( + spi_nor_device, + "Updated to SFDP params: %dKiB w/ %dB pages", + spi_nor_device->capacity >> 10, + spi_nor_device->page_size); + mutex_unlock(&driver_mutex); + } } /* Ensure the device is in a determined addressing state by @@ -764,7 +765,9 @@ static int command_spi_nor_info(int argc, char **argv) spi_nor_device->page_size); /* Get JEDEC ID info. */ - spi_nor_read_jedec_id(spi_nor_device, &mfn_bank, &mfn_id); + rv = spi_nor_read_jedec_id(spi_nor_device, &mfn_bank, &mfn_id); + if (rv != EC_SUCCESS) + return rv; ccprintf("\tJEDEC ID bank %d manufacturing code 0x%x\n", mfn_bank, mfn_id); -- cgit v1.2.1