mtd: ensure that bdi entries are properly initialized and registered

They will be holding dirty inodes and be responsible for flushing
them out, so they need to be setup properly.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

+43 -5
+43 -5
drivers/mtd/mtdcore.c
··· 659 /*====================================================================*/ 660 /* Init code */ 661 662 static int __init init_mtd(void) 663 { 664 int ret; 665 - ret = class_register(&mtd_class); 666 667 - if (ret) { 668 - pr_err("Error registering mtd class: %d\n", ret); 669 - return ret; 670 - } 671 #ifdef CONFIG_PROC_FS 672 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 673 proc_mtd->read_proc = mtd_read_proc; 674 #endif /* CONFIG_PROC_FS */ 675 return 0; 676 } 677 678 static void __exit cleanup_mtd(void) ··· 717 remove_proc_entry( "mtd", NULL); 718 #endif /* CONFIG_PROC_FS */ 719 class_unregister(&mtd_class); 720 } 721 722 module_init(init_mtd);
··· 659 /*====================================================================*/ 660 /* Init code */ 661 662 + static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name) 663 + { 664 + int ret; 665 + 666 + ret = bdi_init(bdi); 667 + if (!ret) 668 + ret = bdi_register(bdi, NULL, name); 669 + 670 + if (ret) 671 + bdi_destroy(bdi); 672 + 673 + return ret; 674 + } 675 + 676 static int __init init_mtd(void) 677 { 678 int ret; 679 680 + ret = class_register(&mtd_class); 681 + if (ret) 682 + goto err_reg; 683 + 684 + ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); 685 + if (ret) 686 + goto err_bdi1; 687 + 688 + ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap"); 689 + if (ret) 690 + goto err_bdi2; 691 + 692 + ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap"); 693 + if (ret) 694 + goto err_bdi3; 695 + 696 #ifdef CONFIG_PROC_FS 697 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 698 proc_mtd->read_proc = mtd_read_proc; 699 #endif /* CONFIG_PROC_FS */ 700 return 0; 701 + 702 + err_bdi3: 703 + bdi_destroy(&mtd_bdi_ro_mappable); 704 + err_bdi2: 705 + bdi_destroy(&mtd_bdi_unmappable); 706 + err_bdi1: 707 + class_unregister(&mtd_class); 708 + err_reg: 709 + pr_err("Error registering mtd class or bdi: %d\n", ret); 710 + return ret; 711 } 712 713 static void __exit cleanup_mtd(void) ··· 682 remove_proc_entry( "mtd", NULL); 683 #endif /* CONFIG_PROC_FS */ 684 class_unregister(&mtd_class); 685 + bdi_destroy(&mtd_bdi_unmappable); 686 + bdi_destroy(&mtd_bdi_ro_mappable); 687 + bdi_destroy(&mtd_bdi_rw_mappable); 688 } 689 690 module_init(init_mtd);