diff options
Diffstat (limited to 'linux-2.4.x/drivers/mtd/chips/chipreg.c')
-rw-r--r-- | linux-2.4.x/drivers/mtd/chips/chipreg.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/linux-2.4.x/drivers/mtd/chips/chipreg.c b/linux-2.4.x/drivers/mtd/chips/chipreg.c index da5512c..51c4952 100644 --- a/linux-2.4.x/drivers/mtd/chips/chipreg.c +++ b/linux-2.4.x/drivers/mtd/chips/chipreg.c @@ -1,5 +1,5 @@ /* - * $Id: chipreg.c,v 1.12 2001/10/02 15:29:53 dwmw2 Exp $ + * $Id: chipreg.c,v 1.19 2005/11/07 11:14:23 gleixner Exp $ * * Registration for chip drivers * @@ -7,12 +7,15 @@ #include <linux/kernel.h> #include <linux/config.h> +#include <linux/module.h> #include <linux/kmod.h> #include <linux/spinlock.h> -#include <linux/mtd/compatmac.h> +#include <linux/slab.h> #include <linux/mtd/map.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/compatmac.h> -spinlock_t chip_drvs_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(chip_drvs_lock); static LIST_HEAD(chip_drvs_list); void register_mtd_chip_driver(struct mtd_chip_driver *drv) @@ -29,7 +32,7 @@ void unregister_mtd_chip_driver(struct mtd_chip_driver *drv) spin_unlock(&chip_drvs_lock); } -static struct mtd_chip_driver *get_mtd_chip_driver (char *name) +static struct mtd_chip_driver *get_mtd_chip_driver (const char *name) { struct list_head *pos; struct mtd_chip_driver *ret = NULL, *this; @@ -38,16 +41,14 @@ static struct mtd_chip_driver *get_mtd_chip_driver (char *name) list_for_each(pos, &chip_drvs_list) { this = list_entry(pos, typeof(*this), list); - + if (!strcmp(this->name, name)) { ret = this; break; } } - if (ret && !try_inc_mod_count(ret->module)) { - /* Eep. Failed. */ + if (ret && !try_module_get(ret->module)) ret = NULL; - } spin_unlock(&chip_drvs_lock); @@ -57,39 +58,53 @@ static struct mtd_chip_driver *get_mtd_chip_driver (char *name) /* Hide all the horrid details, like some silly person taking get_module_symbol() away from us, from the caller. */ -struct mtd_info *do_map_probe(char *name, struct map_info *map) +struct mtd_info *do_map_probe(const char *name, struct map_info *map) { struct mtd_chip_driver *drv; struct mtd_info *ret; drv = get_mtd_chip_driver(name); - if (!drv && !request_module(name)) + if (!drv && !request_module("%s", name)) drv = get_mtd_chip_driver(name); if (!drv) return NULL; ret = drv->probe(map); -#ifdef CONFIG_MODULES - /* We decrease the use count here. It may have been a + + /* We decrease the use count here. It may have been a probe-only module, which is no longer required from this point, having given us a handle on (and increased the use count of) the actual driver code. */ - if(drv->module) - __MOD_DEC_USE_COUNT(drv->module); -#endif + module_put(drv->module); if (ret) return ret; - + return NULL; } +/* + * Destroy an MTD device which was created for a map device. + * Make sure the MTD device is already unregistered before calling this + */ +void map_destroy(struct mtd_info *mtd) +{ + struct map_info *map = mtd->priv; + + if (map->fldrv->destroy) + map->fldrv->destroy(mtd); + + module_put(map->fldrv->module); + + kfree(mtd); +} EXPORT_SYMBOL(register_mtd_chip_driver); EXPORT_SYMBOL(unregister_mtd_chip_driver); EXPORT_SYMBOL(do_map_probe); +EXPORT_SYMBOL(map_destroy); MODULE_LICENSE("GPL"); MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |