aboutsummaryrefslogtreecommitdiff
path: root/drivers/mtd/nand/nand_base.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2006-05-14 01:20:46 +0100
committerDavid Woodhouse <dwmw2@infradead.org>2006-05-14 01:20:46 +0100
commit552d9205186428a1e2a49ed577bcbba9f777af37 (patch)
treed61e09abae0ad18a3beef281384e576d8a54c145 /drivers/mtd/nand/nand_base.c
parent4f678a58d335291ce9213c049bbe16e6d24487ed (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.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index fdaf32083ad..42cff0a2b93 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -69,6 +69,7 @@
*
*/
+#include <linux/module.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/sched.h>
@@ -2316,11 +2317,12 @@ static void nand_resume(struct mtd_info *mtd)
* @mtd: MTD device structure
* @maxchips: Number of chips to scan for
*
- * This fills out all the not initialized function pointers
+ * This fills out all the uninitialized function pointers
* with the defaults.
* The flash ID is read and the mtd/chip structures are
* filled with the appropriate values. Buffers are allocated if
* they are not provided by the board driver
+ * The mtd->owner field must be set to the module of the caller
*
*/
int nand_scan(struct mtd_info *mtd, int maxchips)
@@ -2328,6 +2330,16 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
int i, nand_maf_id, nand_dev_id, busw, maf_id;
struct nand_chip *this = mtd->priv;
+ /* module_text_address() isn't exported. But if _this_ is a module,
+ it's a fairly safe bet that its caller is a module too... and
+ that means the call to module_text_address() gets optimised out
+ without having to resort to ifdefs */
+ if (!mtd->owner && (THIS_MODULE ||
+ module_text_address((unsigned long)__builtin_return_address(0)))) {
+ printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n");
+ BUG();
+ }
+
/* Get buswidth to select the correct functions */
busw = this->options & NAND_BUSWIDTH_16;
@@ -2676,8 +2688,6 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
/* and make the autooob the default one */
memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
- mtd->owner = THIS_MODULE;
-
/* Check, if we should skip the bad block table scan */
if (this->options & NAND_SKIP_BBTSCAN)
return 0;