lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1528708694-19407-1-git-send-email-yogeshnarayan.gaur@nxp.com>
Date:   Mon, 11 Jun 2018 14:48:14 +0530
From:   Yogesh Gaur <yogeshnarayan.gaur@....com>
To:     linux-mtd@...ts.infradead.org
Cc:     boris.brezillon@...tlin.com, boris.brezillon@...e-electrons.com,
        frieder.schrempf@...eet.de, computersforpeace@...il.com,
        david.wolfe@....com, han.xu@....com, festevam@...il.com,
        marek.vasut@...il.com, prabhakar.kushwaha@....com,
        linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org,
        Yogesh Gaur <yogeshnarayan.gaur@....com>,
        NeilBrown <neil@...wn.name>
Subject: [PATCH] mtd: spi-nor: honour max_data_size for spi-nor writes

Honour max_data_size for spi-nor writes
In new spi-mem framework, data size to be written is being calculated
using spi_mem_adjust_op_size().
This can return value less than nor->page_size.

Add check value of data size return from API spi_mem_adjust_op_size()
with the actual requested data size and write, max, only supported
data size.

Signed-off-by: NeilBrown <neil@...wn.name>
Signed-off-by: Yogesh Gaur <yogeshnarayan.gaur@....com>
---
 drivers/mtd/devices/m25p80.c  | 23 ++++++++---------------
 drivers/mtd/spi-nor/spi-nor.c |  7 -------
 2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index e84563d..60224fe 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -72,7 +72,6 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
 				   SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
 				   SPI_MEM_OP_DUMMY(0, 1),
 				   SPI_MEM_OP_DATA_OUT(len, buf, 1));
-	size_t remaining = len;
 	int ret;
 
 	/* get transfer protocols. */
@@ -84,22 +83,16 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
 	if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
 		op.addr.nbytes = 0;
 
-	while (remaining) {
-		op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
-		ret = spi_mem_adjust_op_size(flash->spimem, &op);
-		if (ret)
-			return ret;
-
-		ret = spi_mem_exec_op(flash->spimem, &op);
-		if (ret)
-			return ret;
+	ret = spi_mem_adjust_op_size(flash->spimem, &op);
+	if (ret)
+		return ret;
+	op.data.nbytes = len < op.data.nbytes ? len : op.data.nbytes;
 
-		op.addr.val += op.data.nbytes;
-		remaining -= op.data.nbytes;
-		op.data.buf.out += op.data.nbytes;
-	}
+	ret = spi_mem_exec_op(flash->spimem, &op);
+	if (ret)
+		return ret;
 
-	return len;
+	return op.data.nbytes;
 }
 
 /*
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 5bfa36e..3e63543 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1431,13 +1431,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 			goto write_err;
 		*retlen += written;
 		i += written;
-		if (written != page_remain) {
-			dev_err(nor->dev,
-				"While writing %zu bytes written %zd bytes\n",
-				page_remain, written);
-			ret = -EIO;
-			goto write_err;
-		}
 	}
 
 write_err:
-- 
2.7.4

Patch is based on the spi-mem framework[1]
[1]https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/log/?h=for-4.18

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ