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 659 /*====================================================================*/ 660 660 /* Init code */ 661 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 + 662 676 static int __init init_mtd(void) 663 677 { 664 678 int ret; 665 - ret = class_register(&mtd_class); 666 679 667 - if (ret) { 668 - pr_err("Error registering mtd class: %d\n", ret); 669 - return ret; 670 - } 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 + 671 696 #ifdef CONFIG_PROC_FS 672 697 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 673 698 proc_mtd->read_proc = mtd_read_proc; 674 699 #endif /* CONFIG_PROC_FS */ 675 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; 676 711 } 677 712 678 713 static void __exit cleanup_mtd(void) ··· 717 682 remove_proc_entry( "mtd", NULL); 718 683 #endif /* CONFIG_PROC_FS */ 719 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); 720 688 } 721 689 722 690 module_init(init_mtd);