Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: Replace the expert mode symbols with a single helper

Reduce the number of exported symbols by replacing:
- mtd_expert_analysis_warning (the error string)
- mtd_expert_analysis_mode (the boolean)
with a single helper:
- mtd_check_expert_analysis_mode

Calling this helper will both check/return the content of the internal
boolean -which is not exported anymore- and as well conditionally
WARN_ONCE() the user, like it was done before.

While on this function, make the error string local to the helper and
set it const. Only export this helper when CONFIG_DEBUG_FS is defined to
limit the growth of the Linux kernel size only for a debug feature on
production kernels.

Mechanically update all the consumers.

Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220128113414.1121924-1-miquel.raynal@bootlin.com

+24 -13
+15 -8
drivers/mtd/mtdcore.c
··· 358 358 359 359 DEFINE_SHOW_ATTRIBUTE(mtd_partname_debug); 360 360 361 + static bool mtd_expert_analysis_mode; 362 + 363 + #ifdef CONFIG_DEBUG_FS 364 + bool mtd_check_expert_analysis_mode(void) 365 + { 366 + const char *mtd_expert_analysis_warning = 367 + "Bad block checks have been entirely disabled.\n" 368 + "This is only reserved for post-mortem forensics and debug purposes.\n" 369 + "Never enable this mode if you do not know what you are doing!\n"; 370 + 371 + return WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning); 372 + } 373 + EXPORT_SYMBOL_GPL(mtd_check_expert_analysis_mode); 374 + #endif 375 + 361 376 static struct dentry *dfs_dir_mtd; 362 377 363 378 static void mtd_debugfs_populate(struct mtd_info *mtd) ··· 2384 2369 2385 2370 return ret ? ERR_PTR(ret) : bdi; 2386 2371 } 2387 - 2388 - char *mtd_expert_analysis_warning = 2389 - "Bad block checks have been entirely disabled.\n" 2390 - "This is only reserved for post-mortem forensics and debug purposes.\n" 2391 - "Never enable this mode if you do not know what you are doing!\n"; 2392 - EXPORT_SYMBOL_GPL(mtd_expert_analysis_warning); 2393 - bool mtd_expert_analysis_mode; 2394 - EXPORT_SYMBOL_GPL(mtd_expert_analysis_mode); 2395 2372 2396 2373 static struct proc_dir_entry *proc_mtd; 2397 2374
+1 -1
drivers/mtd/nand/core.c
··· 21 21 */ 22 22 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos) 23 23 { 24 - if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning)) 24 + if (mtd_check_expert_analysis_mode()) 25 25 return false; 26 26 27 27 if (nanddev_bbt_is_initialized(nand)) {
+1 -1
drivers/mtd/nand/raw/nand_base.c
··· 321 321 if (nand_region_is_secured(chip, ofs, mtd->erasesize)) 322 322 return -EIO; 323 323 324 - if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning)) 324 + if (mtd_check_expert_analysis_mode()) 325 325 return 0; 326 326 327 327 if (chip->legacy.block_bad)
+1 -1
drivers/mtd/nand/raw/nand_bbt.c
··· 1455 1455 pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1456 1456 (unsigned int)offs, block, res); 1457 1457 1458 - if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning)) 1458 + if (mtd_check_expert_analysis_mode()) 1459 1459 return 0; 1460 1460 1461 1461 switch (res) {
+6 -2
include/linux/mtd/mtd.h
··· 711 711 712 712 unsigned mtd_mmap_capabilities(struct mtd_info *mtd); 713 713 714 - extern char *mtd_expert_analysis_warning; 715 - extern bool mtd_expert_analysis_mode; 714 + #ifdef CONFIG_DEBUG_FS 715 + bool mtd_check_expert_analysis_mode(void); 716 + #else 717 + static inline bool mtd_check_expert_analysis_mode(void) { return false; } 718 + #endif 719 + 716 720 717 721 #endif /* __MTD_MTD_H__ */