From 5b9062f3f64b15008aeef5753b477256634933da Mon Sep 17 00:00:00 2001 From: Marshall Dawson Date: Fri, 13 Dec 2019 17:32:53 -0700 Subject: soc/amd/common: Correct SPI FIFO size check When checking that command and data fit in the FIFO, don't count the first byte. The command doesn't go through the FIFO. TEST=confirm error (4+68>71) goes away on Mandolin BUG=b:146225550 Change-Id: Ica2ca514deea401c9c5396913087e07a12ab3cf3 Signed-off-by: Marshall Dawson Reviewed-on: https://review.coreboot.org/c/coreboot/+/37721 Tested-by: build bot (Jenkins) Reviewed-by: Raul Rangel Reviewed-by: Eric Peers Reviewed-by: Frans Hendriks Reviewed-by: Martin Roth --- src/soc/amd/common/block/spi/fch_spi_flash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/soc/amd/common/block') diff --git a/src/soc/amd/common/block/spi/fch_spi_flash.c b/src/soc/amd/common/block/spi/fch_spi_flash.c index d8eeefc7ed..b05c1a4a14 100644 --- a/src/soc/amd/common/block/spi/fch_spi_flash.c +++ b/src/soc/amd/common/block/spi/fch_spi_flash.c @@ -40,7 +40,8 @@ int fch_spi_flash_cmd_write(const u8 *cmd, size_t cmd_len, const void *data, siz int ret; u8 buff[SPI_FIFO_DEPTH + 1]; - if ((cmd_len + data_len) > SPI_FIFO_DEPTH) + /* Ensure FIFO is large enough. First byte of command does not go in the FIFO. */ + if ((cmd_len - 1 + data_len) > SPI_FIFO_DEPTH) return -1; memcpy(buff, cmd, cmd_len); memcpy(buff + cmd_len, data, data_len); -- cgit v1.2.3