Use a distinct return code for SPI commands with unsupported/invalid length
Some drivers support only a few combinations of read/write length and
return error otherwise. Having a distinct return code for this error
means we can handle it in upper layers.
Corresponding to flashrom svn r653.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
diff --git a/ichspi.c b/ichspi.c
index 6ad55bb..73dc249 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -599,10 +599,16 @@
{
switch (spi_controller) {
case SPI_CONTROLLER_VIA:
+ if (datalength > 16)
+ return SPI_INVALID_LENGTH;
return ich7_run_opcode(op, offset, datalength, data, 16);
case SPI_CONTROLLER_ICH7:
+ if (datalength > 64)
+ return SPI_INVALID_LENGTH;
return ich7_run_opcode(op, offset, datalength, data, 64);
case SPI_CONTROLLER_ICH9:
+ if (datalength > 64)
+ return SPI_INVALID_LENGTH;
return ich9_run_opcode(op, offset, datalength, data);
default:
printf_debug("%s: unsupported chipset\n", __FUNCTION__);
@@ -686,6 +692,7 @@
const unsigned char *writearr, unsigned char *readarr)
{
int a;
+ int result;
int opcode_index = -1;
const unsigned char cmd = *writearr;
OPCODE *opcode;
@@ -728,10 +735,10 @@
count = readcnt;
}
- if (run_opcode(*opcode, addr, count, data) != 0) {
+ result = run_opcode(*opcode, addr, count, data);
+ if (result) {
printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);
- return 1;
}
- return 0;
+ return result;
}