summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorBastian Krause <bst@pengutronix.de>2019-08-01 11:19:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-05 11:34:20 +0200
commit3adce7def29d79b4f01216becf9a7fd0f8765e88 (patch)
treedcc70d622f80621d98ee033a8433ceb4897c9b64 /drivers/mtd
parentf43a5d60824101221530bbf804132bdf5e3a5fec (diff)
downloadbarebox-3adce7def29d79b4f01216becf9a7fd0f8765e88.tar.gz
barebox-3adce7def29d79b4f01216becf9a7fd0f8765e88.tar.xz
mtd: spi-nor: fix page offset/remains calculation in spi_nor_write
nor->write() simply adds the number of written bytes to the pointer given. Thus retval is incremented in each loop cycle for each spi_nor_write() call without ever resetting it. This leads to wrong page offset/remains calculations and an incorrect number of bytes written to retlen. This becomes apparant only if the calling function actually compares len and retlen (e.g. mtd_peb_write() ). Otherwise wrong data is written: $ memcpy -s /dev/prng -d prng_data 0 0 10k $ erase /dev/mtd0.mypart $ cp prng_data /dev/mtd0.mypart $ memcmp -s prng_data -d /dev/mtd0.mypart 0 0 memcmp returned "files differ" before, with this patch it returns "OK". Fixes: c8516869c4 ("spi: Extend the core to ease integration of SPI memory controllers") Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index b2052ce0af..9dbc8302ed 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -972,6 +972,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
for (i = 0; i < len; ) {
ssize_t written;
+ retval = 0;
page_offset = (to + i) & (nor->page_size - 1);
page_remain = min_t(size_t, nor->page_size - page_offset,