From patchwork Thu Mar 26 11:42:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 244322 List-Id: U-Boot discussion From: rasmus.villemoes at prevas.dk (Rasmus Villemoes) Date: Thu, 26 Mar 2020 12:42:55 +0100 Subject: [PATCH 1/3] mtd: spi-nor: don't guard stm_*lock* family by preprocessor conditionals In-Reply-To: <20200326114257.1782-1-rasmus.villemoes@prevas.dk> References: <20200326114257.1782-1-rasmus.villemoes@prevas.dk> Message-ID: <20200326114257.1782-2-rasmus.villemoes@prevas.dk> Use C instead of cpp to choose whether the stm_lock and friends get compiled in. This provides better compile testing and reduces the amount of #ifdeffery. All of the previously guarded functions are static, so this does not add anything to the binary in the !(SPI_FLASH_STMICRO or SPI_FLASH_SST) case (and even if they were not static, the linker would eventually remove them). The test of SPI_FLASH_STMICRO or SPI_FLASH_SST is done inside the test for specific manufacturers or SPI_NOR_HAS_LOCK in flags, to prepare for adding support for locking on Macronix flashes. The compiler is perfectly capabable of compiling if (expression with no side effects) { if (0) { } } to nothing at all. Signed-off-by: Rasmus Villemoes --- drivers/mtd/spi/spi-nor-core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 7b6ad495ac..af83d813fc 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -591,7 +591,6 @@ erase_err: return ret; } -#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST) /* Write status register and ensure bits in mask match written values */ static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask) { @@ -877,7 +876,6 @@ static int stm_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len) return stm_is_locked_sr(nor, ofs, len, status); } -#endif /* CONFIG_SPI_FLASH_STMICRO */ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) { @@ -2528,17 +2526,17 @@ int spi_nor_scan(struct spi_nor *nor) mtd->_erase = spi_nor_erase; mtd->_read = spi_nor_read; -#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST) /* NOR protection support for STmicro/Micron chips and similar */ if (JEDEC_MFR(info) == SNOR_MFR_ST || JEDEC_MFR(info) == SNOR_MFR_MICRON || JEDEC_MFR(info) == SNOR_MFR_SST || info->flags & SPI_NOR_HAS_LOCK) { - nor->flash_lock = stm_lock; - nor->flash_unlock = stm_unlock; - nor->flash_is_locked = stm_is_locked; + if (IS_ENABLED(CONFIG_SPI_FLASH_STMICRO) || IS_ENABLED(CONFIG_SPI_FLASH_SST)) { + nor->flash_lock = stm_lock; + nor->flash_unlock = stm_unlock; + nor->flash_is_locked = stm_is_locked; + } } -#endif #ifdef CONFIG_SPI_FLASH_SST /*