summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2017-04-12 06:24:37 -0400
committerJens Axboe <axboe@fb.com>2017-04-20 14:09:55 -0400
commitfa06052d637bf3a76f18cd2304048b866af4096e (patch)
tree7516fc2e1008907e50a7f860d3f21aee65638223
parentedd3ba94c4e5ef6ec045d5730d365d557fb54f98 (diff)
mtd: Convert to dynamically allocated bdi infrastructure
MTD already allocates backing_dev_info dynamically. Convert it to use generic infrastructure for this including proper refcounting. We drop mtd->backing_dev_info as its only use was to pass mtd_bdi pointer from one file into another and if we wanted to keep that in a clean way, we'd have to make mtd hold and drop bdi reference as needed which seems pointless for passing one global pointer... CC: David Woodhouse <dwmw2@infradead.org> CC: Brian Norris <computersforpeace@gmail.com> CC: linux-mtd@lists.infradead.org Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/mtd/mtdcore.c23
-rw-r--r--drivers/mtd/mtdsuper.c7
-rw-r--r--include/linux/mtd/mtd.h5
3 files changed, 18 insertions, 17 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 66a9dedd1062..23e2e56ca54e 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -46,7 +46,7 @@
46 46
47#include "mtdcore.h" 47#include "mtdcore.h"
48 48
49static struct backing_dev_info *mtd_bdi; 49struct backing_dev_info *mtd_bdi;
50 50
51#ifdef CONFIG_PM_SLEEP 51#ifdef CONFIG_PM_SLEEP
52 52
@@ -496,11 +496,9 @@ int add_mtd_device(struct mtd_info *mtd)
496 * mtd_device_parse_register() multiple times on the same master MTD, 496 * mtd_device_parse_register() multiple times on the same master MTD,
497 * especially with CONFIG_MTD_PARTITIONED_MASTER=y. 497 * especially with CONFIG_MTD_PARTITIONED_MASTER=y.
498 */ 498 */
499 if (WARN_ONCE(mtd->backing_dev_info, "MTD already registered\n")) 499 if (WARN_ONCE(mtd->dev.type, "MTD already registered\n"))
500 return -EEXIST; 500 return -EEXIST;
501 501
502 mtd->backing_dev_info = mtd_bdi;
503
504 BUG_ON(mtd->writesize == 0); 502 BUG_ON(mtd->writesize == 0);
505 mutex_lock(&mtd_table_mutex); 503 mutex_lock(&mtd_table_mutex);
506 504
@@ -1775,13 +1773,18 @@ static struct backing_dev_info * __init mtd_bdi_init(char *name)
1775 struct backing_dev_info *bdi; 1773 struct backing_dev_info *bdi;
1776 int ret; 1774 int ret;
1777 1775
1778 bdi = kzalloc(sizeof(*bdi), GFP_KERNEL); 1776 bdi = bdi_alloc(GFP_KERNEL);
1779 if (!bdi) 1777 if (!bdi)
1780 return ERR_PTR(-ENOMEM); 1778 return ERR_PTR(-ENOMEM);
1781 1779
1782 ret = bdi_setup_and_register(bdi, name); 1780 bdi->name = name;
1781 /*
1782 * We put '-0' suffix to the name to get the same name format as we
1783 * used to get. Since this is called only once, we get a unique name.
1784 */
1785 ret = bdi_register(bdi, NULL, "%.28s-0", name);
1783 if (ret) 1786 if (ret)
1784 kfree(bdi); 1787 bdi_put(bdi);
1785 1788
1786 return ret ? ERR_PTR(ret) : bdi; 1789 return ret ? ERR_PTR(ret) : bdi;
1787} 1790}
@@ -1813,8 +1816,7 @@ static int __init init_mtd(void)
1813out_procfs: 1816out_procfs:
1814 if (proc_mtd) 1817 if (proc_mtd)
1815 remove_proc_entry("mtd", NULL); 1818 remove_proc_entry("mtd", NULL);
1816 bdi_destroy(mtd_bdi); 1819 bdi_put(mtd_bdi);
1817 kfree(mtd_bdi);
1818err_bdi: 1820err_bdi:
1819 class_unregister(&mtd_class); 1821 class_unregister(&mtd_class);
1820err_reg: 1822err_reg:
@@ -1828,8 +1830,7 @@ static void __exit cleanup_mtd(void)
1828 if (proc_mtd) 1830 if (proc_mtd)
1829 remove_proc_entry("mtd", NULL); 1831 remove_proc_entry("mtd", NULL);
1830 class_unregister(&mtd_class); 1832 class_unregister(&mtd_class);
1831 bdi_destroy(mtd_bdi); 1833 bdi_put(mtd_bdi);
1832 kfree(mtd_bdi);
1833 idr_destroy(&mtd_idr); 1834 idr_destroy(&mtd_idr);
1834} 1835}
1835 1836
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index 20c02a3b7417..e69e7855e31f 100644
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -18,6 +18,7 @@
18#include <linux/ctype.h> 18#include <linux/ctype.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/major.h> 20#include <linux/major.h>
21#include <linux/backing-dev.h>
21 22
22/* 23/*
23 * compare superblocks to see if they're equivalent 24 * compare superblocks to see if they're equivalent
@@ -38,6 +39,8 @@ static int get_sb_mtd_compare(struct super_block *sb, void *_mtd)
38 return 0; 39 return 0;
39} 40}
40 41
42extern struct backing_dev_info *mtd_bdi;
43
41/* 44/*
42 * mark the superblock by the MTD device it is using 45 * mark the superblock by the MTD device it is using
43 * - set the device number to be the correct MTD block device for pesuperstence 46 * - set the device number to be the correct MTD block device for pesuperstence
@@ -49,7 +52,9 @@ static int get_sb_mtd_set(struct super_block *sb, void *_mtd)
49 52
50 sb->s_mtd = mtd; 53 sb->s_mtd = mtd;
51 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index); 54 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
52 sb->s_bdi = mtd->backing_dev_info; 55 sb->s_bdi = bdi_get(mtd_bdi);
56 sb->s_iflags |= SB_I_DYNBDI;
57
53 return 0; 58 return 0;
54} 59}
55 60
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eebdc63cf6af..79b176eca04a 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -334,11 +334,6 @@ struct mtd_info {
334 int (*_get_device) (struct mtd_info *mtd); 334 int (*_get_device) (struct mtd_info *mtd);
335 void (*_put_device) (struct mtd_info *mtd); 335 void (*_put_device) (struct mtd_info *mtd);
336 336
337 /* Backing device capabilities for this device
338 * - provides mmap capabilities
339 */
340 struct backing_dev_info *backing_dev_info;
341
342 struct notifier_block reboot_notifier; /* default mode before reboot */ 337 struct notifier_block reboot_notifier; /* default mode before reboot */
343 338
344 /* ECC status information */ 339 /* ECC status information */