summaryrefslogtreecommitdiffstats
path: root/linux_spi.c
diff options
context:
space:
mode:
authorMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>2012-03-06 22:17:06 +0000
committerMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>2012-03-06 22:17:06 +0000
commit8371d7238a404fb9713c2ff4a011263709c38c34 (patch)
tree5e061ffcfcac316ebb7e346317fe3b86bcb68bdb /linux_spi.c
parent2c3e9d5f57b8f2c33bda30dcac043c1b31089183 (diff)
downloadast2050-flashrom-8371d7238a404fb9713c2ff4a011263709c38c34.zip
ast2050-flashrom-8371d7238a404fb9713c2ff4a011263709c38c34.tar.gz
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. Corresponding to flashrom svn r1513. Signed-off-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'linux_spi.c')
-rw-r--r--linux_spi.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/linux_spi.c b/linux_spi.c
index 2ae681f..17d003e 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -130,6 +130,7 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
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 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
if (fd == -1)
return -1;
-
- if (ioctl(fd, SPI_IOC_MESSAGE(2), msg) == -1) {
+ /* The implementation currently does not support requests that
+ don't start with sending a command. */
+ if (writecnt == 0)
+ return SPI_INVALID_LENGTH;
+
+ /* 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;
}
OpenPOWER on IntegriCloud