[flashrom] [PATCH 04/12] use the max_data_read field of the new spi_programmer struct to simplify run_opcode.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Wed Jun 8 04:55:31 CEST 2011


Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 ichspi.c |   41 +++++++++++++++++------------------------
 1 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/ichspi.c b/ichspi.c
index 12727d1..dff6f32 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -913,37 +913,30 @@ static int ich9_run_opcode(OPCODE op, uint32_t offset,
 static int run_opcode(OPCODE op, uint32_t offset,
 		      uint8_t datalength, uint8_t * data)
 {
+	uint8_t maxlength = spi_programmer->max_data_read;
+
+	if (spi_programmer->type == SPI_CONTROLLER_NONE) {
+		msg_perr("%s: unsupported chipset\n", __func__);
+		return -1;
+	}
+
+	if (datalength > maxlength) {
+		msg_perr("%s: Internal command size error for "
+			"opcode 0x%02x, got datalength=%i, want <=%i\n",
+			__func__, op.opcode, datalength, maxlength);
+		return SPI_INVALID_LENGTH;
+	}
+
 	switch (spi_programmer->type) {
 	case SPI_CONTROLLER_VIA:
-		if (datalength > 16) {
-			msg_perr("%s: Internal command size error for "
-				"opcode 0x%02x, got datalength=%i, want <=16\n",
-				__func__, op.opcode, datalength);
-			return SPI_INVALID_LENGTH;
-		}
-		return ich7_run_opcode(op, offset, datalength, data, 16);
 	case SPI_CONTROLLER_ICH7:
-		if (datalength > 64) {
-			msg_perr("%s: Internal command size error for "
-				"opcode 0x%02x, got datalength=%i, want <=16\n",
-				__func__, op.opcode, datalength);
-			return SPI_INVALID_LENGTH;
-		}
-		return ich7_run_opcode(op, offset, datalength, data, 64);
+		return ich7_run_opcode(op, offset, datalength, data, maxlength);
 	case SPI_CONTROLLER_ICH9:
-		if (datalength > 64) {
-			msg_perr("%s: Internal command size error for "
-				"opcode 0x%02x, got datalength=%i, want <=16\n",
-				__func__, op.opcode, datalength);
-			return SPI_INVALID_LENGTH;
-		}
 		return ich9_run_opcode(op, offset, datalength, data);
 	default:
-		msg_perr("%s: unsupported chipset\n", __func__);
+		/* If we ever get here, something really weird happened */
+		return -1;
 	}
-
-	/* If we ever get here, something really weird happened */
-	return -1;
 }
 
 static int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
-- 
1.7.1





More information about the flashrom mailing list