%patch Index: q/drivers/mtd/mtdcore.c =================================================================== --- q.orig/drivers/mtd/mtdcore.c Tue Aug 5 16:46:21 2003 +++ q/drivers/mtd/mtdcore.c Tue Aug 5 16:46:38 2003 @@ -36,30 +36,39 @@ static LIST_HEAD(mtd_notifiers); /** - * add_mtd_device - register an MTD device + * add_mtd_device_full - register an MTD device at a particular minor number * @mtd: pointer to new MTD device info structure + * @minor: requested minor number. -1 to for the first free. * - * 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) + * Add a device to the list of MTD devices present in the system, + * and notifies each currently active MTD 'user' of its + * arrival. Returns zero on success or 1 on failure, which + * currently only occurs if the requested minor number has + * already been allocated or if minor exceeds MAX_MTD_DEVICES + * (i.e. 16) */ - -int add_mtd_device(struct mtd_info *mtd) +int add_mtd_device_full(struct mtd_info *mtd, int minor) { - int i; - down(&mtd_table_mutex); - for (i=0; i < MAX_MTD_DEVICES; i++) - if (!mtd_table[i]) { + if ( minor == -1 ) { + for (minor = 0; minor < MAX_MTD_DEVICES; minor++) + if (!mtd_table[minor]) + break; + } + + if ( minor >= MAX_MTD_DEVICES || minor < 0 || mtd_table[minor] ) { + up(&mtd_table_mutex); + return 1; + } + struct list_head *this; - mtd_table[i] = mtd; - mtd->index = i; + mtd_table[minor] = mtd; + mtd->index = minor; mtd->usecount = 0; - DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name); + DEBUG(0, "mtd: Giving out device %d to %s\n",minor, mtd->name); /* No need to get a refcount on the module containing the notifier, since we hold the mtd_table_mutex */ list_for_each(this, &mtd_notifiers) { @@ -76,8 +85,18 @@ return 0; } - up(&mtd_table_mutex); - return 1; +/** + * add_mtd_device - register an MTD device + * @mtd: pointer to new MTD device info structure + * + * 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) + */ +int add_mtd_device(struct mtd_info *mtd) +{ + return add_mtd_device_full(mtd, -1); } /** @@ -288,6 +307,7 @@ EXPORT_SYMBOL(add_mtd_device); +EXPORT_SYMBOL(add_mtd_device_full); EXPORT_SYMBOL(del_mtd_device); EXPORT_SYMBOL(get_mtd_device); EXPORT_SYMBOL(put_mtd_device); Index: q/include/linux/mtd/mtd.h =================================================================== --- q.orig/include/linux/mtd/mtd.h Tue Aug 5 16:46:22 2003 +++ q/include/linux/mtd/mtd.h Tue Aug 5 16:46:38 2003 @@ -238,6 +238,7 @@ /* Kernel-side ioctl definitions */ extern int add_mtd_device(struct mtd_info *mtd); +extern int add_mtd_device_full(struct mtd_info *mtd, int minor); extern int del_mtd_device (struct mtd_info *mtd); extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); %diffstat drivers/mtd/mtdcore.c | 52 +++++++++++++++++++++++++++++++++--------------- include/linux/mtd/mtd.h | 1 2 files changed, 37 insertions(+), 16 deletions(-)