Skip to content

Commit

Permalink
mtd: Replace the expert mode symbols with a single helper
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Miquel Raynal <[email protected]>
Link: https://lore.kernel.org/linux-mtd/[email protected]
  • Loading branch information
miquelraynal committed Feb 7, 2022
1 parent 69a6d06 commit ad5e35f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
23 changes: 15 additions & 8 deletions drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ static int mtd_partname_debug_show(struct seq_file *s, void *p)

DEFINE_SHOW_ATTRIBUTE(mtd_partname_debug);

static bool mtd_expert_analysis_mode;

#ifdef CONFIG_DEBUG_FS
bool mtd_check_expert_analysis_mode(void)
{
const char *mtd_expert_analysis_warning =
"Bad block checks have been entirely disabled.\n"
"This is only reserved for post-mortem forensics and debug purposes.\n"
"Never enable this mode if you do not know what you are doing!\n";

return WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning);
}
EXPORT_SYMBOL_GPL(mtd_check_expert_analysis_mode);
#endif

static struct dentry *dfs_dir_mtd;

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

char *mtd_expert_analysis_warning =
"Bad block checks have been entirely disabled.\n"
"This is only reserved for post-mortem forensics and debug purposes.\n"
"Never enable this mode if you do not know what you are doing!\n";
EXPORT_SYMBOL_GPL(mtd_expert_analysis_warning);
bool mtd_expert_analysis_mode;
EXPORT_SYMBOL_GPL(mtd_expert_analysis_mode);

static struct proc_dir_entry *proc_mtd;

static int __init init_mtd(void)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos)
{
if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
if (mtd_check_expert_analysis_mode())
return false;

if (nanddev_bbt_is_initialized(nand)) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs)
if (nand_region_is_secured(chip, ofs, mtd->erasesize))
return -EIO;

if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
if (mtd_check_expert_analysis_mode())
return 0;

if (chip->legacy.block_bad)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_bbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ int nand_isbad_bbt(struct nand_chip *this, loff_t offs, int allowbbt)
pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
(unsigned int)offs, block, res);

if (WARN_ONCE(mtd_expert_analysis_mode, mtd_expert_analysis_warning))
if (mtd_check_expert_analysis_mode())
return 0;

switch (res) {
Expand Down
8 changes: 6 additions & 2 deletions include/linux/mtd/mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,11 @@ static inline int mtd_is_bitflip_or_eccerr(int err) {

unsigned mtd_mmap_capabilities(struct mtd_info *mtd);

extern char *mtd_expert_analysis_warning;
extern bool mtd_expert_analysis_mode;
#ifdef CONFIG_DEBUG_FS
bool mtd_check_expert_analysis_mode(void);
#else
static inline bool mtd_check_expert_analysis_mode(void) { return false; }
#endif


#endif /* __MTD_MTD_H__ */

0 comments on commit ad5e35f

Please sign in to comment.