Signed-off-by: Al Viro --- diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index e7dc732..e32ccc7 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -93,7 +93,7 @@ static int mtd_open(struct inode *inode, struct file *file) return -EACCES; mutex_lock(&mtd_mutex); - mtd = get_mtd_device(NULL, devnum); + mtd = get_mtd_device(devnum); if (IS_ERR(mtd)) { ret = PTR_ERR(mtd); diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index b01993e..7953565 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -572,25 +572,15 @@ int unregister_mtd_user (struct mtd_notifier *old) * error code if not. */ -struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) +struct mtd_info *get_mtd_device(int num) { - struct mtd_info *ret = NULL, *other; + struct mtd_info *ret = NULL; int err = -ENODEV; mutex_lock(&mtd_table_mutex); - if (num == -1) { - mtd_for_each_device(other) { - if (other == mtd) { - ret = mtd; - break; - } - } - } else if (num >= 0) { + if (num >= 0) ret = idr_find(&mtd_idr, num); - if (mtd && mtd != ret) - ret = NULL; - } if (!ret) { ret = ERR_PTR(err); diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c index a90bfe7..f04fb55 100644 --- a/drivers/mtd/mtdsuper.c +++ b/drivers/mtd/mtdsuper.c @@ -107,7 +107,7 @@ static struct dentry *mount_mtd_nr(struct file_system_type *fs_type, int flags, { struct mtd_info *mtd; - mtd = get_mtd_device(NULL, mtdnr); + mtd = get_mtd_device(mtdnr); if (IS_ERR(mtd)) { pr_debug("MTDSB: Device #%u doesn't appear to exist\n", mtdnr); return ERR_CAST(mtd); diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 933f7e5..9f89b71 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -375,7 +375,7 @@ static int __init mtd_oobtest_init(void) printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index afafb69..ac3ed7b 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -513,7 +513,7 @@ static int __init mtd_pagetest_init(void) printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 550fe51..7658fdd 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -178,7 +178,7 @@ static int __init mtd_readtest_init(void) printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: Cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index 493b367..0703763 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -373,7 +373,7 @@ static int __init mtd_speedtest_init(void) else printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 52ffd91..a66f416 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -259,7 +259,7 @@ static int __init mtd_stresstest_init(void) printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 1a05bfa..75244b5 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -388,7 +388,7 @@ static int __init mtd_subpagetest_init(void) printk(PRINT_PREF "MTD device: %d\n", dev); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 03ab649..40f48fa 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -228,7 +228,7 @@ static int __init tort_init(void) pgcnt); printk(PRINT_PREF "write verify %s\n", check ? "enabled" : "disabled"); - mtd = get_mtd_device(NULL, dev); + mtd = get_mtd_device(dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 6c3fb5a..d920f46 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -1141,7 +1141,7 @@ static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) */ return ERR_PTR(-EINVAL); - return get_mtd_device(NULL, minor / 2); + return get_mtd_device(minor / 2); } /** @@ -1171,7 +1171,7 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev) /* Probably this is an MTD character device node path */ mtd = open_mtd_by_chdev(mtd_dev); } else - mtd = get_mtd_device(NULL, mtd_num); + mtd = get_mtd_device(mtd_num); return mtd; } diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 3320a50..a0fe796 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c @@ -1000,7 +1000,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, break; } - mtd = get_mtd_device(NULL, req.mtd_num); + mtd = get_mtd_device(req.mtd_num); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); break; diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index a9c309a..0c320c9 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -53,7 +53,7 @@ u16 mtd_Flash_Init(void) return FAIL; } - spectra_mtd = get_mtd_device(NULL, mtddev); + spectra_mtd = get_mtd_device(mtddev); if (!spectra_mtd) { printk(KERN_ERR "Failed to obtain MTD device #%d\n", mtddev); return FAIL; diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 339e17e..e4ee211 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -267,7 +267,7 @@ static const struct logfs_device_ops mtd_devops = { int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr) { - struct mtd_info *mtd = get_mtd_device(NULL, mtdnr); + struct mtd_info *mtd = get_mtd_device(mtdnr); if (IS_ERR(mtd)) return PTR_ERR(mtd); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9f5b312..9a70edd 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -322,7 +322,7 @@ extern int mtd_device_parse_register(struct mtd_info *mtd, #define mtd_device_register(master, parts, nr_parts) \ mtd_device_parse_register(master, NULL, NULL, parts, nr_parts) extern int mtd_device_unregister(struct mtd_info *master); -extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); +extern struct mtd_info *get_mtd_device(int num); extern int __get_mtd_device(struct mtd_info *mtd); extern void __put_mtd_device(struct mtd_info *mtd); extern struct mtd_info *get_mtd_device_nm(const char *name);