Hi Vignesh,

On 12.12.18 18:32, Vignesh R wrote:
Now that there is new SPI NOR framework, simplify mtd device
registration and read/write/erase operations.

Signed-off-by: Vignesh R <vigne...@ti.com>
---
  drivers/mtd/spi/sf_internal.h |  2 +-
  drivers/mtd/spi/sf_mtd.c      | 52 ++++++++++++++---------------------
  drivers/mtd/spi/sf_probe.c    |  5 ++--
  3 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 7e7d400cdbdf..8b445bb0b506 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -99,6 +99,6 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash);
#ifdef CONFIG_SPI_FLASH_MTD
  int spi_flash_mtd_register(struct spi_flash *flash);
-void spi_flash_mtd_unregister(void);
+void spi_flash_mtd_unregister(struct spi_flash *flash);
  #endif
  #endif /* _SF_INTERNAL_H_ */
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
index 68c36002bee2..65185b7c57dc 100644
--- a/drivers/mtd/spi/sf_mtd.c
+++ b/drivers/mtd/spi/sf_mtd.c
@@ -9,21 +9,19 @@
  #include <linux/mtd/mtd.h>
  #include <spi_flash.h>
-static struct mtd_info sf_mtd_info;
  static bool sf_mtd_registered;
  static char sf_mtd_name[8];
static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
  {
-       struct spi_flash *flash = mtd->priv;
        int err;
- if (!flash)
+       if (!mtd || !mtd->priv)
                return -ENODEV;
instr->state = MTD_ERASING; - err = spi_flash_erase(flash, instr->addr, instr->len);
+       err = mtd->_erase(mtd, instr);
        if (err) {
                instr->state = MTD_ERASE_FAILED;
                instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
@@ -39,13 +37,12 @@ static int spi_flash_mtd_erase(struct mtd_info *mtd, struct 
erase_info *instr)
  static int spi_flash_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
        size_t *retlen, u_char *buf)
  {
-       struct spi_flash *flash = mtd->priv;
        int err;
- if (!flash)
+       if (!mtd || !mtd->priv)
                return -ENODEV;
- err = spi_flash_read(flash, from, len, buf);
+       err = mtd->_read(mtd, from, len, retlen, buf);
        if (!err)
                *retlen = len;

I just tested this patchset on my MIPS linkit smart platform and it
hangs in an infinite loop here in this read function. The callstack
is:

spi_flash_std_read -> spi_flash_mtd_read

spi_flash_mtd_read() now calls itself recursively.

Any ideas?

Thanks,
Stefan
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to