From a67b3719f32673a9890700c72b980acbd2749e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Tue, 5 Oct 2021 15:56:01 +0200 Subject: mtd: spi-flash: Check for zero length in legacy spi_flash_*() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check for zero length in the legacy spi_flash_read() / spi_flash_write() / spi_flash_erase() functions. On zero length, return 0 immediately, don't call the underlying method. Rationale: - these legacy functions call the _read(), _write() and _erase() methods of struct mtd - the DM callers of these methods already check for zero length - making all callers of these methods check for zero length makes it possible to remove the check from implementations of these _read(), _write() and _erase() methods Signed-off-by: Marek BehĂșn --- include/spi_flash.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/spi_flash.h b/include/spi_flash.h index 3d747c925b9..4d4ae89c192 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -165,6 +165,9 @@ static inline int spi_flash_read(struct spi_flash *flash, u32 offset, struct mtd_info *mtd = &flash->mtd; size_t retlen; + if (!len) + return 0; + return mtd->_read(mtd, offset, len, &retlen, buf); } @@ -174,6 +177,9 @@ static inline int spi_flash_write(struct spi_flash *flash, u32 offset, struct mtd_info *mtd = &flash->mtd; size_t retlen; + if (!len) + return 0; + return mtd->_write(mtd, offset, len, &retlen, buf); } @@ -188,6 +194,9 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, return -EINVAL; } + if (!len) + return 0; + memset(&instr, 0, sizeof(instr)); instr.addr = offset; instr.len = len; -- cgit v1.2.3 From 0d1ecc99cb59c2190257f7738f91db21f174dc02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Tue, 5 Oct 2021 15:56:06 +0200 Subject: mtd: Remove mtd_erase_callback() entirely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original purpose of mtd_erase_callback() in Linux at the time it was imported to U-Boot, was to inform the caller that erasing is done (since it was an asynchronous operation). All supplied callback methods in U-Boot do nothing, but the mtd_erase_callback() function was (until previous patch) grossly abused in U-Boot's mtdpart implementation for completely different purpose. Since we got rid of the abusement, remove the mtd_erase_callback() function and the .callback member from struct erase_info entirely, in order to avoid such problems in the future. Signed-off-by: Marek BehĂșn --- include/linux/mtd/mtd.h | 11 ----------- include/nand.h | 1 - 2 files changed, 12 deletions(-) (limited to 'include') diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 3b302fb8c31..74554009815 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -51,7 +51,6 @@ struct erase_info { u_long retries; unsigned dev; unsigned cell; - void (*callback) (struct erase_info *self); u_long priv; u_char state; struct erase_info *next; @@ -535,16 +534,6 @@ extern int unregister_mtd_user (struct mtd_notifier *old); #endif void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size); -#ifdef CONFIG_MTD_PARTITIONS -void mtd_erase_callback(struct erase_info *instr); -#else -static inline void mtd_erase_callback(struct erase_info *instr) -{ - if (instr->callback) - instr->callback(instr); -} -#endif - static inline int mtd_is_bitflip(int err) { return err == -EUCLEAN; } diff --git a/include/nand.h b/include/nand.h index 75c605193ab..09dbda4e81b 100644 --- a/include/nand.h +++ b/include/nand.h @@ -69,7 +69,6 @@ static inline int nand_erase(struct mtd_info *info, loff_t off, size_t size) instr.mtd = info; instr.addr = off; instr.len = size; - instr.callback = 0; return mtd_erase(info, &instr); } -- cgit v1.2.3