
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 rasmus.villemoes@prevas.dk --- 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 /*