Skip to contentSkip to conversation

mtd: m25p80: consider max message size in m25p80_read

PATCH In review Heiner Kallweit 1 participant 1 message Aug 7, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 mtd: m25p80: consider max message size in m25p80_read

If the spi_master has the max_message_size_flag set, the maximum amount of data that can be read is the message size limit minus length of the read command.

---
 drivers/mtd/devices/m25p80.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mtd/devices/m25p80.c +6 -1
index 9cf7fcd..2925038 100644
@@ -133,6 +133,7 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 	struct spi_transfer t[2];
 	struct spi_message m;
 	unsigned int dummy = nor->read_dummy;
+	size_t max_read_len;
 	ssize_t ret;
 
 	/* convert the dummy cycles to the number of bytes */
@@ -170,9 +171,13 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 	t[0].len = m25p_cmdsz(nor) + dummy;
 	spi_message_add_tail(&t[0], &m);
 
+	max_read_len = spi_max_transfer_size(spi);
+	if (spi->master->max_message_size_flag)
+		max_read_len -= t[0].len;
+
 	t[1].rx_buf = buf;
 	t[1].rx_nbits = m25p80_rx_nbits(nor);
-	t[1].len = min(len, spi_max_transfer_size(spi));
+	t[1].len = min(len, max_read_len);
 	spi_message_add_tail(&t[1], &m);
 
 	ret = spi_sync(spi, &m);
Signature · 6 lines
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html