diff options
author | Marshall Dawson <marshalldawson3rd@gmail.com> | 2017-11-18 18:01:21 -0700 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2017-11-21 01:36:27 +0000 |
commit | 0e022038fc4b02d9df304765d2c4259c4cc7e1bf (patch) | |
tree | a16cc79071ed263bf2873b3aa7cc1893f9bfc0be /src/soc/amd/stoneyridge | |
parent | a85f8b94ab7663c5799b94d5a4d4953fa5ac5838 (diff) |
amd/stoneyridge/spi: Fix reads greater than 5 bytes
This corrects a bug in 918c8717 "amd/stoneyridge: Add SPI controller
driver". Pass a pointer to din to the do_command() function so the
caller's copy is correctly updated. The bug allowed reads <= 5 bytes
to work correctly (3 bytes consumed in the FIFO by the address) but
overwrote data in the din buffer on larger transfers.
Change-Id: I32b7752f047112849871cafc9ae33c5ea1466ee1
Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Reviewed-on: https://review.coreboot.org/22519
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/soc/amd/stoneyridge')
-rw-r--r-- | src/soc/amd/stoneyridge/spi.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/soc/amd/stoneyridge/spi.c b/src/soc/amd/stoneyridge/spi.c index 84b56dfa3d..cf8157cc42 100644 --- a/src/soc/amd/stoneyridge/spi.c +++ b/src/soc/amd/stoneyridge/spi.c @@ -114,7 +114,7 @@ void spi_init(void) } static int do_command(uint8_t cmd, const void *dout, - size_t bytesout, void *din, size_t *bytesin) + size_t bytesout, uint8_t **din, size_t *bytesin) { size_t count; size_t max_in = MIN(*bytesin, SPI_FIFO_DEPTH); @@ -138,8 +138,8 @@ static int do_command(uint8_t cmd, const void *dout, for (count = 0; count < bytesout; count++) spi_read8(SPI_CNTRL1); /* skip the bytes we sent */ - for (count = 0; count < max_in; count++, din++) - *(uint8_t *)din = spi_read8(SPI_CNTRL1); + for (count = 0; count < max_in; count++, (*din)++) + **din = spi_read8(SPI_CNTRL1); *bytesin -= max_in; return 0; @@ -168,7 +168,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, } do { - if (do_command(cmd, dout, bytesout, din, &bytesin)) + if (do_command(cmd, dout, bytesout, (uint8_t **)&din, &bytesin)) return -1; } while (bytesin); |