Skip to content

Commit ad5e35f

Browse files
committed
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
1 parent 69a6d06 commit ad5e35f

5 files changed

Lines changed: 24 additions & 13 deletions

File tree

drivers/mtd/mtdcore.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,21 @@ static int mtd_partname_debug_show(struct seq_file *s, void *p)
358358

359359
DEFINE_SHOW_ATTRIBUTE(mtd_partname_debug);
360360

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+
361376
static struct dentry *dfs_dir_mtd;
362377

363378
static void mtd_debugfs_populate(struct mtd_info *mtd)
@@ -2370,14 +2385,6 @@ static struct backing_dev_info * __init mtd_bdi_init(const char *name)
23702385
return ret ? ERR_PTR(ret) : bdi;
23712386
}
23722387

2373-
char *mtd_expert_analysis_warning =
2374-
"Bad block checks have been entirely disabled.\n"
2375-
"This is only reserved for post-mortem forensics and debug purposes.\n"
2376-
"Never enable this mode if you do not know what you are doing!\n";
2377-
EXPORT_SYMBOL_GPL(mtd_expert_analysis_warning);
2378-
bool mtd_expert_analysis_mode;
2379-
EXPORT_SYMBOL_GPL(mtd_expert_analysis_mode);
2380-
23812388
static struct proc_dir_entry *proc_mtd;
23822389

23832390
static int __init init_mtd(void)

drivers/mtd/nand/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos)
2323
{
24-
if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
24+
if (mtd_check_expert_analysis_mode())
2525
return false;
2626

2727
if (nanddev_bbt_is_initialized(nand)) {

drivers/mtd/nand/raw/nand_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs)
321321
if (nand_region_is_secured(chip, ofs, mtd->erasesize))
322322
return -EIO;
323323

324-
if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
324+
if (mtd_check_expert_analysis_mode())
325325
return 0;
326326

327327
if (chip->legacy.block_bad)

drivers/mtd/nand/raw/nand_bbt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ int nand_isbad_bbt(struct nand_chip *this, loff_t offs, int allowbbt)
14551455
pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
14561456
(unsigned int)offs, block, res);
14571457

1458-
if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
1458+
if (mtd_check_expert_analysis_mode())
14591459
return 0;
14601460

14611461
switch (res) {

include/linux/mtd/mtd.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,11 @@ static inline int mtd_is_bitflip_or_eccerr(int err) {
711711

712712
unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
713713

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+
716720

717721
#endif /* __MTD_MTD_H__ */

0 commit comments

Comments
 (0)