[flashrom] [commit] r1513 - trunk

repository service svn at flashrom.org
Tue Mar 6 23:17:08 CET 2012


Author: mkarcher
Date: Tue Mar  6 23:17:06 2012
New Revision: 1513
URL: http://flashrom.org/trac/flashrom/changeset/1513

Log:
Prevent submission of empty read requests in linux_spi.

The submission of zero-sized read requests in a write-only transaction
fails at least for omap2_mcspi drivers and is pointless in general.

This patch does not address the implementation of zero-sized writes (which
would need to skip the write command), as there are no flash transactions
not starting with a command.

Signed-off-by: Michael Karcher <flashrom at mkarcher.dialup.fu-berlin.de>
Acked-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>

Modified:
   trunk/linux_spi.c

Modified: trunk/linux_spi.c
==============================================================================
--- trunk/linux_spi.c	Sat Mar  3 19:09:33 2012	(r1512)
+++ trunk/linux_spi.c	Tue Mar  6 23:17:06 2012	(r1513)
@@ -130,6 +130,7 @@
 				  const unsigned char *txbuf,
 				  unsigned char *rxbuf)
 {
+	int iocontrol_code;
 	struct spi_ioc_transfer msg[2] = {
 		{
 			.tx_buf = (uint64_t)(ptrdiff_t)txbuf,
@@ -143,8 +144,19 @@
 
 	if (fd == -1)
 		return -1;
+	/* The implementation currently does not support requests that
+	   don't start with sending a command. */
+	if (writecnt == 0)
+		return SPI_INVALID_LENGTH;
 
-	if (ioctl(fd, SPI_IOC_MESSAGE(2), msg) == -1) {
+	/* Just submit the first (write) request in case there is nothing
+	   to read. Otherwise submit both requests. */
+	if (readcnt == 0)
+		iocontrol_code = SPI_IOC_MESSAGE(1);
+	else
+		iocontrol_code = SPI_IOC_MESSAGE(2);
+
+	if (ioctl(fd, iocontrol_code, msg) == -1) {
 		msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno));
 		return -1;
 	}




More information about the flashrom mailing list