Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1395534

[PATCH v7 05/10] mtd: nxp-spifi: return amount of data transferred or error in read/write

From Brian Norris <computersforpeace@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v7 05/10] mtd: nxp-spifi: return amount of data transferred or error in read/write
Date 2016-05-06 02:40 +0200
Message-ID <rvBYf-2li-43@gated-at.bofh.it> (permalink)
References <rvBYd-2li-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Add checking of SPI transfer errors and return them from read/write
functions. Also return the amount of data transferred.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
New in v7

 drivers/mtd/spi-nor/nxp-spifi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/nxp-spifi.c b/drivers/mtd/spi-nor/nxp-spifi.c
index 187adba5e69f..b0fb86996b8f 100644
--- a/drivers/mtd/spi-nor/nxp-spifi.c
+++ b/drivers/mtd/spi-nor/nxp-spifi.c
@@ -185,7 +185,7 @@ static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
 	memcpy_fromio(buf, spifi->flash_base + from, len);
 	*retlen += len;
 
-	return 0;
+	return len;
 }
 
 static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
@@ -194,6 +194,7 @@ static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
 	struct nxp_spifi *spifi = nor->priv;
 	u32 cmd;
 	int ret;
+	size_t i;
 
 	ret = nxp_spifi_set_memory_mode_off(spifi);
 	if (ret)
@@ -209,10 +210,14 @@ static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
 	      SPIFI_CMD_FRAMEFORM(spifi->nor.addr_width + 1);
 	writel(cmd, spifi->io_base + SPIFI_CMD);
 
-	while (len--)
-		writeb(*buf++, spifi->io_base + SPIFI_DATA);
+	for (i = 0; i < len; i++)
+		writeb(buf[i], spifi->io_base + SPIFI_DATA);
 
-	return nxp_spifi_wait_for_cmd(spifi);
+	ret = nxp_spifi_wait_for_cmd(spifi);
+	if (ret)
+		return ret;
+
+	return len;
 }
 
 static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs)
-- 
2.8.0.rc3.226.g39d4020

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v7 00/10] Add error checking to spi-nor read and write Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200
  [PATCH v7 05/10] mtd: nxp-spifi: return amount of data transferred or error in read/write Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200
  [PATCH v7 03/10] mtd: fsl-quadspi: return amount of data read/written or error Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200
  [PATCH v7 09/10] mtd: spi-nor: add read loop Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200
  [PATCH v7 07/10] mtd: spi-nor: stop passing around retlen Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200
  [PATCH v7 04/10] mtd: mtk-quadspi: return amount of data transferred or error in read/write Brian Norris <computersforpeace@gmail.com> - 2016-05-06 02:40 +0200

csiph-web