1096-mtd-spi-nor-add-read-loop.patch 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From b5929f91416d64afacf46c649f38cc8f0eea50d2 Mon Sep 17 00:00:00 2001
  2. From: Michal Suchanek <hramrach@gmail.com>
  3. Date: Wed, 2 Dec 2015 10:38:20 +0000
  4. Subject: [PATCH 096/113] mtd: spi-nor: add read loop
  5. mtdblock and ubi do not handle the situation when read returns less data
  6. than requested. Loop in spi-nor until buffer is filled or an error is
  7. returned.
  8. Signed-off-by: Michal Suchanek <hramrach@gmail.com>
  9. Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
  10. ---
  11. drivers/mtd/spi-nor/spi-nor.c | 20 ++++++++++++++------
  12. 1 file changed, 14 insertions(+), 6 deletions(-)
  13. --- a/drivers/mtd/spi-nor/spi-nor.c
  14. +++ b/drivers/mtd/spi-nor/spi-nor.c
  15. @@ -927,14 +927,22 @@ static int spi_nor_read(struct mtd_info
  16. if (ret)
  17. return ret;
  18. - ret = nor->read(nor, from, len, buf);
  19. + while (len) {
  20. + ret = nor->read(nor, from, len, buf);
  21. + if (ret <= 0)
  22. + goto read_err;
  23. - spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
  24. - if (ret < 0)
  25. - return ret;
  26. + WARN_ON(ret > len);
  27. + *retlen += ret;
  28. + buf += ret;
  29. + from += ret;
  30. + len -= ret;
  31. + }
  32. + ret = 0;
  33. - *retlen += ret;
  34. - return 0;
  35. +read_err:
  36. + spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
  37. + return ret;
  38. }
  39. static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,