[coreboot-gerrit] Change in coreboot[master]: amd/stoneyridge/spi: Fix reads greater than 5 bytes

Marshall Dawson (Code Review) gerrit at coreboot.org
Sun Nov 19 02:09:16 CET 2017


Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/22519


Change subject: amd/stoneyridge/spi: Fix reads greater than 5 bytes
......................................................................

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 at gmail.com>
---
M src/soc/amd/stoneyridge/spi.c
1 file changed, 4 insertions(+), 5 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/22519/1

diff --git a/src/soc/amd/stoneyridge/spi.c b/src/soc/amd/stoneyridge/spi.c
index 84b56df..7ff2676 100644
--- a/src/soc/amd/stoneyridge/spi.c
+++ b/src/soc/amd/stoneyridge/spi.c
@@ -114,7 +114,7 @@
 }
 
 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 @@
 	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;
@@ -166,9 +166,8 @@
 				" chip driver use spi_crop_chunk()?\n");
 		return -1;
 	}
-
 	do {
-		if (do_command(cmd, dout, bytesout, din, &bytesin))
+		if (do_command(cmd, dout, bytesout, (uint8_t **)&din, &bytesin))
 			return -1;
 	} while (bytesin);
 

-- 
To view, visit https://review.coreboot.org/22519
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I32b7752f047112849871cafc9ae33c5ea1466ee1
Gerrit-Change-Number: 22519
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20171119/aa78e81e/attachment.html>


More information about the coreboot-gerrit mailing list