Loading drivers/mtd/mtdcore.c +80 −71 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <linux/init.h> #include <linux/mtd/compatmac.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/mtd/mtd.h> #include "internal.h" Loading @@ -33,13 +34,18 @@ static struct class mtd_class = { .resume = mtd_cls_resume, }; static DEFINE_IDR(mtd_idr); /* These are exported solely for the purpose of mtd_blkdevs.c. You should not use them for _anything_ else */ DEFINE_MUTEX(mtd_table_mutex); struct mtd_info *mtd_table[MAX_MTD_DEVICES]; EXPORT_SYMBOL_GPL(mtd_table_mutex); EXPORT_SYMBOL_GPL(mtd_table); struct mtd_info *__mtd_next_device(int i) { return idr_get_next(&mtd_idr, &i); } EXPORT_SYMBOL_GPL(__mtd_next_device); static LIST_HEAD(mtd_notifiers); Loading Loading @@ -235,13 +241,13 @@ static struct device_type mtd_devtype = { * Add a device to the list of MTD devices present in the system, and * notify each currently active MTD 'user' of its arrival. Returns * zero on success or 1 on failure, which currently will only happen * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16) * or there's a sysfs error. * if there is insufficient memory or a sysfs error. */ int add_mtd_device(struct mtd_info *mtd) { int i; struct mtd_notifier *not; int i, error; if (!mtd->backing_dev_info) { switch (mtd->type) { Loading @@ -260,11 +266,15 @@ int add_mtd_device(struct mtd_info *mtd) BUG_ON(mtd->writesize == 0); mutex_lock(&mtd_table_mutex); for (i=0; i < MAX_MTD_DEVICES; i++) if (!mtd_table[i]) { struct mtd_notifier *not; do { if (!idr_pre_get(&mtd_idr, GFP_KERNEL)) goto fail_locked; error = idr_get_new(&mtd_idr, mtd, &i); } while (error == -EAGAIN); if (error) goto fail_locked; mtd_table[i] = mtd; mtd->index = i; mtd->usecount = 0; Loading @@ -286,8 +296,7 @@ int add_mtd_device(struct mtd_info *mtd) && (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) { if (mtd->unlock(mtd, 0, mtd->size)) printk(KERN_WARNING "%s: unlock failed, " "writes may not work\n", "%s: unlock failed, writes may not work\n", mtd->name); } Loading @@ -299,10 +308,8 @@ int add_mtd_device(struct mtd_info *mtd) mtd->dev.devt = MTD_DEVT(i); dev_set_name(&mtd->dev, "mtd%d", i); dev_set_drvdata(&mtd->dev, mtd); if (device_register(&mtd->dev) != 0) { mtd_table[i] = NULL; break; } if (device_register(&mtd->dev) != 0) goto fail_added; if (MTD_DEVT(i)) device_create(&mtd_class, mtd->dev.parent, Loading @@ -322,8 +329,10 @@ int add_mtd_device(struct mtd_info *mtd) either. :) */ __module_get(THIS_MODULE); return 0; } fail_added: idr_remove(&mtd_idr, i); fail_locked: mutex_unlock(&mtd_table_mutex); return 1; } Loading @@ -344,7 +353,7 @@ int del_mtd_device (struct mtd_info *mtd) mutex_lock(&mtd_table_mutex); if (mtd_table[mtd->index] != mtd) { if (idr_find(&mtd_idr, mtd->index) != mtd) { ret = -ENODEV; } else if (mtd->usecount) { printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n", Loading @@ -360,7 +369,7 @@ int del_mtd_device (struct mtd_info *mtd) list_for_each_entry(not, &mtd_notifiers, list) not->remove(mtd); mtd_table[mtd->index] = NULL; idr_remove(&mtd_idr, mtd->index); module_put(THIS_MODULE); ret = 0; Loading Loading @@ -448,8 +457,8 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) break; } } } else if (num >= 0 && num < MAX_MTD_DEVICES) { ret = mtd_table[num]; } else if (num >= 0) { ret = idr_find(&mtd_idr, num); if (mtd && mtd != ret) ret = NULL; } Loading drivers/mtd/mtdcore.h +1 −11 Original line number Diff line number Diff line Loading @@ -8,17 +8,7 @@ should not use them for _anything_ else */ extern struct mutex mtd_table_mutex; extern struct mtd_info *mtd_table[MAX_MTD_DEVICES]; static inline struct mtd_info *__mtd_next_device(int i) { while (i < MAX_MTD_DEVICES) { if (mtd_table[i]) return mtd_table[i]; i++; } return NULL; } extern struct mtd_info *__mtd_next_device(int i); #define mtd_for_each_device(mtd) \ for ((mtd) = __mtd_next_device(0); \ Loading include/linux/mtd/mtd.h +0 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #define MTD_CHAR_MAJOR 90 #define MTD_BLOCK_MAJOR 31 #define MAX_MTD_DEVICES 32 #define MTD_ERASE_PENDING 0x01 #define MTD_ERASING 0x02 Loading Loading
drivers/mtd/mtdcore.c +80 −71 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <linux/init.h> #include <linux/mtd/compatmac.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/mtd/mtd.h> #include "internal.h" Loading @@ -33,13 +34,18 @@ static struct class mtd_class = { .resume = mtd_cls_resume, }; static DEFINE_IDR(mtd_idr); /* These are exported solely for the purpose of mtd_blkdevs.c. You should not use them for _anything_ else */ DEFINE_MUTEX(mtd_table_mutex); struct mtd_info *mtd_table[MAX_MTD_DEVICES]; EXPORT_SYMBOL_GPL(mtd_table_mutex); EXPORT_SYMBOL_GPL(mtd_table); struct mtd_info *__mtd_next_device(int i) { return idr_get_next(&mtd_idr, &i); } EXPORT_SYMBOL_GPL(__mtd_next_device); static LIST_HEAD(mtd_notifiers); Loading Loading @@ -235,13 +241,13 @@ static struct device_type mtd_devtype = { * Add a device to the list of MTD devices present in the system, and * notify each currently active MTD 'user' of its arrival. Returns * zero on success or 1 on failure, which currently will only happen * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16) * or there's a sysfs error. * if there is insufficient memory or a sysfs error. */ int add_mtd_device(struct mtd_info *mtd) { int i; struct mtd_notifier *not; int i, error; if (!mtd->backing_dev_info) { switch (mtd->type) { Loading @@ -260,11 +266,15 @@ int add_mtd_device(struct mtd_info *mtd) BUG_ON(mtd->writesize == 0); mutex_lock(&mtd_table_mutex); for (i=0; i < MAX_MTD_DEVICES; i++) if (!mtd_table[i]) { struct mtd_notifier *not; do { if (!idr_pre_get(&mtd_idr, GFP_KERNEL)) goto fail_locked; error = idr_get_new(&mtd_idr, mtd, &i); } while (error == -EAGAIN); if (error) goto fail_locked; mtd_table[i] = mtd; mtd->index = i; mtd->usecount = 0; Loading @@ -286,8 +296,7 @@ int add_mtd_device(struct mtd_info *mtd) && (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) { if (mtd->unlock(mtd, 0, mtd->size)) printk(KERN_WARNING "%s: unlock failed, " "writes may not work\n", "%s: unlock failed, writes may not work\n", mtd->name); } Loading @@ -299,10 +308,8 @@ int add_mtd_device(struct mtd_info *mtd) mtd->dev.devt = MTD_DEVT(i); dev_set_name(&mtd->dev, "mtd%d", i); dev_set_drvdata(&mtd->dev, mtd); if (device_register(&mtd->dev) != 0) { mtd_table[i] = NULL; break; } if (device_register(&mtd->dev) != 0) goto fail_added; if (MTD_DEVT(i)) device_create(&mtd_class, mtd->dev.parent, Loading @@ -322,8 +329,10 @@ int add_mtd_device(struct mtd_info *mtd) either. :) */ __module_get(THIS_MODULE); return 0; } fail_added: idr_remove(&mtd_idr, i); fail_locked: mutex_unlock(&mtd_table_mutex); return 1; } Loading @@ -344,7 +353,7 @@ int del_mtd_device (struct mtd_info *mtd) mutex_lock(&mtd_table_mutex); if (mtd_table[mtd->index] != mtd) { if (idr_find(&mtd_idr, mtd->index) != mtd) { ret = -ENODEV; } else if (mtd->usecount) { printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n", Loading @@ -360,7 +369,7 @@ int del_mtd_device (struct mtd_info *mtd) list_for_each_entry(not, &mtd_notifiers, list) not->remove(mtd); mtd_table[mtd->index] = NULL; idr_remove(&mtd_idr, mtd->index); module_put(THIS_MODULE); ret = 0; Loading Loading @@ -448,8 +457,8 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) break; } } } else if (num >= 0 && num < MAX_MTD_DEVICES) { ret = mtd_table[num]; } else if (num >= 0) { ret = idr_find(&mtd_idr, num); if (mtd && mtd != ret) ret = NULL; } Loading
drivers/mtd/mtdcore.h +1 −11 Original line number Diff line number Diff line Loading @@ -8,17 +8,7 @@ should not use them for _anything_ else */ extern struct mutex mtd_table_mutex; extern struct mtd_info *mtd_table[MAX_MTD_DEVICES]; static inline struct mtd_info *__mtd_next_device(int i) { while (i < MAX_MTD_DEVICES) { if (mtd_table[i]) return mtd_table[i]; i++; } return NULL; } extern struct mtd_info *__mtd_next_device(int i); #define mtd_for_each_device(mtd) \ for ((mtd) = __mtd_next_device(0); \ Loading
include/linux/mtd/mtd.h +0 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #define MTD_CHAR_MAJOR 90 #define MTD_BLOCK_MAJOR 31 #define MAX_MTD_DEVICES 32 #define MTD_ERASE_PENDING 0x01 #define MTD_ERASING 0x02 Loading