diff options
author | David Woodhouse <dwmw2@infradead.org> | 2006-05-13 20:20:46 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2006-05-13 20:20:46 -0400 |
commit | 552d9205186428a1e2a49ed577bcbba9f777af37 (patch) | |
tree | d61e09abae0ad18a3beef281384e576d8a54c145 /drivers/mtd/nand/nand_base.c | |
parent | 4f678a58d335291ce9213c049bbe16e6d24487ed (diff) |
[MTD] Fix module refcounting in NAND board drivers.
The _board_ driver needs to be mtd->owner, and it in turn pins the
nand.ko module. Fix them all to actually do that, and fix nand.ko not to
overwrite it -- and also to check that the caller sets it, if the caller
is a module.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index fdaf32083ada..42cff0a2b93d 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -69,6 +69,7 @@ | |||
69 | * | 69 | * |
70 | */ | 70 | */ |
71 | 71 | ||
72 | #include <linux/module.h> | ||
72 | #include <linux/delay.h> | 73 | #include <linux/delay.h> |
73 | #include <linux/errno.h> | 74 | #include <linux/errno.h> |
74 | #include <linux/sched.h> | 75 | #include <linux/sched.h> |
@@ -2316,11 +2317,12 @@ static void nand_resume(struct mtd_info *mtd) | |||
2316 | * @mtd: MTD device structure | 2317 | * @mtd: MTD device structure |
2317 | * @maxchips: Number of chips to scan for | 2318 | * @maxchips: Number of chips to scan for |
2318 | * | 2319 | * |
2319 | * This fills out all the not initialized function pointers | 2320 | * This fills out all the uninitialized function pointers |
2320 | * with the defaults. | 2321 | * with the defaults. |
2321 | * The flash ID is read and the mtd/chip structures are | 2322 | * The flash ID is read and the mtd/chip structures are |
2322 | * filled with the appropriate values. Buffers are allocated if | 2323 | * filled with the appropriate values. Buffers are allocated if |
2323 | * they are not provided by the board driver | 2324 | * they are not provided by the board driver |
2325 | * The mtd->owner field must be set to the module of the caller | ||
2324 | * | 2326 | * |
2325 | */ | 2327 | */ |
2326 | int nand_scan(struct mtd_info *mtd, int maxchips) | 2328 | int nand_scan(struct mtd_info *mtd, int maxchips) |
@@ -2328,6 +2330,16 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2328 | int i, nand_maf_id, nand_dev_id, busw, maf_id; | 2330 | int i, nand_maf_id, nand_dev_id, busw, maf_id; |
2329 | struct nand_chip *this = mtd->priv; | 2331 | struct nand_chip *this = mtd->priv; |
2330 | 2332 | ||
2333 | /* module_text_address() isn't exported. But if _this_ is a module, | ||
2334 | it's a fairly safe bet that its caller is a module too... and | ||
2335 | that means the call to module_text_address() gets optimised out | ||
2336 | without having to resort to ifdefs */ | ||
2337 | if (!mtd->owner && (THIS_MODULE || | ||
2338 | module_text_address((unsigned long)__builtin_return_address(0)))) { | ||
2339 | printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n"); | ||
2340 | BUG(); | ||
2341 | } | ||
2342 | |||
2331 | /* Get buswidth to select the correct functions */ | 2343 | /* Get buswidth to select the correct functions */ |
2332 | busw = this->options & NAND_BUSWIDTH_16; | 2344 | busw = this->options & NAND_BUSWIDTH_16; |
2333 | 2345 | ||
@@ -2676,8 +2688,6 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2676 | /* and make the autooob the default one */ | 2688 | /* and make the autooob the default one */ |
2677 | memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); | 2689 | memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); |
2678 | 2690 | ||
2679 | mtd->owner = THIS_MODULE; | ||
2680 | |||
2681 | /* Check, if we should skip the bad block table scan */ | 2691 | /* Check, if we should skip the bad block table scan */ |
2682 | if (this->options & NAND_SKIP_BBTSCAN) | 2692 | if (this->options & NAND_SKIP_BBTSCAN) |
2683 | return 0; | 2693 | return 0; |