--- zzzz-none-000/linux-4.1.52/drivers/mtd/mtdcore.c 2018-05-28 02:26:45.000000000 +0000 +++ bcm63-7530ax-731/linux-4.1.52/drivers/mtd/mtdcore.c 2022-03-02 11:37:13.000000000 +0000 @@ -1235,6 +1235,43 @@ .llseek = seq_lseek, .release = single_release, }; + +/*====================================================================*/ +/* Support for /proc/mtd */ +#if defined(CONFIG_AVM_ENHANCED) +static struct proc_dir_entry *proc_bbt_mtd; +static int mtd_bbt_proc_show(struct seq_file *m, void *v) +{ + struct mtd_info *mtd; + + mutex_lock(&mtd_table_mutex); + mtd_for_each_device(mtd) { + if (mtd->_block_isbad) { + uint64_t i; + unsigned int badblocks = 0; + for (i = 0; i < mtd->size; i += mtd->erasesize) { + if (mtd->_block_isbad(mtd, i) && ((badblocks + 1) > badblocks)) + badblocks++; + } + seq_printf(m, "mtd%d: %u bad blocks\n", mtd->index, badblocks); + } + } + mutex_unlock(&mtd_table_mutex); + return 0; +} + +static int mtd_bbt_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, mtd_bbt_proc_show, NULL); +} + +static const struct file_operations mtd_bbt_proc_ops = { + .open = mtd_bbt_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif /*--- #if #defined(CONFIG_AVM_ENHANCED) ---*/ #endif /* CONFIG_PROC_FS */ /*====================================================================*/ @@ -1274,6 +1311,10 @@ if (ret) goto out_procfs; +#if defined(CONFIG_AVM_ENHANCED) + proc_bbt_mtd = proc_create("avm/mtd_bbt", 0, NULL, &mtd_bbt_proc_ops); +#endif + return 0; out_procfs: @@ -1291,6 +1332,11 @@ cleanup_mtdchar(); if (proc_mtd) remove_proc_entry("mtd", NULL); + +#if defined(CONFIG_AVM_ENHANCED) + if (proc_bbt_mtd) + remove_proc_entry("mtd_bbt", NULL); +#endif class_unregister(&mtd_class); bdi_destroy(&mtd_bdi); }