From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Roese Date: Thu, 13 Dec 2018 08:46:00 +0100 Subject: [U-Boot] [PATCH 09/16] sf_mtd: Simply mtd operations In-Reply-To: <20181212173228.12281-10-vigneshr@ti.com> References: <20181212173228.12281-1-vigneshr@ti.com> <20181212173228.12281-10-vigneshr@ti.com> Message-ID: <12b8574a-4327-2515-13d0-5f4fe540e11d@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > --- > 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 > #include > > -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