From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Suchanek Subject: [PATCH v6 07/10] mtd: spi-nor: add read loop Date: 2 Dec 2015 10:38:20 -0000 Message-ID: <42c51bf17e21a5ae658174000f14035a56b0879b.1449052427.git.hramrach@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Heiner Kallweit , David Woodhouse , Brian Norris , Han Xu , Mark Brown , Michal Suchanek , Boris Brezillon , Javier Martinez Canillas , "Rafal Milecki" , Jagan Teki , "Andrew F. Davis" , Mika Westerberg , Gabor Juhos , "Bean Huo " , Furquan Shaikh , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+gldm-linux-mtd-36=gmane.org@lists.infradead.org List-Id: linux-spi.vger.kernel.org mtdblock and ubi do not handle the situation when read returns less data than requested. Loop in spi-nor until buffer is filled or an error is returned. Signed-off-by: Michal Suchanek --- - use WARN_ON rather than BUG_ON --- drivers/mtd/spi-nor/spi-nor.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 115c123..ded79ae 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -907,14 +907,22 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, if (ret) return ret; - ret = nor->read(nor, from, len, buf); + while (len) { + ret = nor->read(nor, from, len, buf); + if (ret <= 0) + goto read_err; + + WARN_ON(ret > len); + *retlen += ret; + buf += ret; + from += ret; + len -= ret; + } + ret = 0; +read_err: spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ); - if (ret < 0) - return ret; - - *retlen += ret; - return 0; + return ret; } static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, -- 2.6.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/