mtd: introduce mtd_can_have_bb helper
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 2 Jan 2012 11:48:54 +0000 (13:48 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:26:24 +0000 (18:26 +0000)
This patch introduces new 'mtd_can_have_bb()' helper function which checks
whether the flash can have bad eraseblocks. Then it changes all the
direct 'mtd->block_isbad' use cases with 'mtd_can_have_bb()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 files changed:
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdoops.c
drivers/mtd/mtdswap.c
drivers/mtd/nftlcore.c
drivers/mtd/redboot.c
drivers/mtd/tests/mtd_readtest.c
drivers/mtd/tests/mtd_speedtest.c
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_torturetest.c
drivers/mtd/ubi/build.c
include/linux/mtd/mtd.h

index 92da621b1425a34690239f07eaa5a68ef693e0a8..64efcbf087e92d11012787bdc0873f4c863b36be 100644 (file)
@@ -867,10 +867,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 
                if (copy_from_user(&offs, argp, sizeof(loff_t)))
                        return -EFAULT;
-               if (!mtd->block_isbad)
-                       ret = -EOPNOTSUPP;
-               else
-                       return mtd_block_isbad(mtd, offs);
+               return mtd_block_isbad(mtd, offs);
                break;
        }
 
index aaafb5e187653a6365560f7cf77c2ee80f529b57..fbf3cb124a93f9779a70206382e0025ee2b2d95f 100644 (file)
@@ -647,7 +647,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
        struct mtd_concat *concat = CONCAT(mtd);
        int i, res = 0;
 
-       if (!concat->subdev[0]->block_isbad)
+       if (!mtd_can_have_bb(concat->subdev[0]))
                return res;
 
        if (ofs > mtd->size)
index c8540b8a7fc6cf4f987cf4045ca35a62db2d060c..a4c8f67560e0eecd5494ced3561e8e4ac4bb0110 100644 (file)
@@ -169,7 +169,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
                        cxt->nextpage = 0;
        }
 
-       while (mtd->block_isbad) {
+       while (mtd_can_have_bb(mtd)) {
                ret = mtd_block_isbad(mtd, cxt->nextpage * record_size);
                if (!ret)
                        break;
@@ -257,7 +257,7 @@ static void find_next_position(struct mtdoops_context *cxt)
        size_t retlen;
 
        for (page = 0; page < cxt->oops_pages; page++) {
-               if (mtd->block_isbad &&
+               if (mtd_can_have_bb(mtd) &&
                    mtd_block_isbad(mtd, page * record_size))
                        continue;
                /* Assume the page is used */
index fe4426c1c73699ad522a080eed699aa905d5ff9b..3fc8cb2756c0fac1064ca26315e2a771c703973a 100644 (file)
@@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
        offset = mtdswap_eb_offset(d, eb);
 
        /* Check first if the block is bad. */
-       if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset))
+       if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset))
                return MTDSWAP_SCANNED_BAD;
 
        ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
@@ -1058,7 +1058,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size)
 
        badcnt = 0;
 
-       if (mtd->block_isbad)
+       if (mtd_can_have_bb(mtd))
                for (offset = 0; offset < size; offset += mtd->erasesize)
                        if (mtd_block_isbad(mtd, offset))
                                badcnt++;
index 8847e60ad167e9b38b840519ea512a9b24d4bdcb..a75382aff5f68d17f419307b70eb4427f7c07507 100644 (file)
@@ -56,7 +56,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
        if (memcmp(mtd->name, "DiskOnChip", 10))
                return;
 
-       if (!mtd->block_isbad) {
+       if (!mtd_can_have_bb(mtd)) {
                printk(KERN_ERR
 "NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n"
 "Please use the new diskonchip driver under the NAND subsystem.\n");
index 09bb81ea3a7ebc8a631f8729c729cd70e98d6ddb..48970c14beffd911fd154e53dd3b56690f03d4f9 100644 (file)
@@ -78,7 +78,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
 
        if ( directory < 0 ) {
                offset = master->size + directory * master->erasesize;
-               while (master->block_isbad && 
+               while (mtd_can_have_bb(master) &&
                       mtd_block_isbad(master, offset)) {
                        if (!offset) {
                        nogood:
@@ -89,7 +89,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
                }
        } else {
                offset = directory * master->erasesize;
-               while (master->block_isbad && 
+               while (mtd_can_have_bb(master) &&
                       mtd_block_isbad(master, offset)) {
                        offset += master->erasesize;
                        if (offset == master->size)
index 4228eb4e54c7f91be50704c3353597eae7ef21db..121aba189cec6de33297a2afb88ecd7892d329f5 100644 (file)
@@ -148,8 +148,7 @@ static int scan_for_bad_eraseblocks(void)
                return -ENOMEM;
        }
 
-       /* NOR flash does not implement block_isbad */
-       if (mtd->block_isbad == NULL)
+       if (!mtd_can_have_bb(mtd))
                return 0;
 
        printk(PRINT_PREF "scanning for bad eraseblocks\n");
index 4d2ed5c0807ded9e0053e6c38f54d659106a04aa..2aec4f3b72be3d9975ce92d83b1fdd063872a95b 100644 (file)
@@ -336,8 +336,7 @@ static int scan_for_bad_eraseblocks(void)
                return -ENOMEM;
        }
 
-       /* NOR flash does not implement block_isbad */
-       if (mtd->block_isbad == NULL)
+       if (!mtd_can_have_bb(mtd))
                goto out;
 
        printk(PRINT_PREF "scanning for bad eraseblocks\n");
index 399aa2bf220dc235a9e7ced91bd1ee76afd2516e..7b33f22d0b583196ae0a7fb5ccd6563293e239af 100644 (file)
@@ -227,8 +227,7 @@ static int scan_for_bad_eraseblocks(void)
                return -ENOMEM;
        }
 
-       /* NOR flash does not implement block_isbad */
-       if (mtd->block_isbad == NULL)
+       if (!mtd_can_have_bb(mtd))
                return 0;
 
        printk(PRINT_PREF "scanning for bad eraseblocks\n");
index 557105f2ead344cb27db5ced9a13c92fea8ac78c..b65861bc7b8e59397df4b8469774dcb4881705cf 100644 (file)
@@ -290,7 +290,7 @@ static int __init tort_init(void)
         * Check if there is a bad eraseblock among those we are going to test.
         */
        memset(&bad_ebs[0], 0, sizeof(int) * ebcnt);
-       if (mtd->block_isbad) {
+       if (mtd_can_have_bb(mtd)) {
                for (i = eb; i < eb + ebcnt; i++) {
                        err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize);
 
index 6c3fb5ab20f5723f3e97ce203bf28d274ee85f38..115749f20f9e5402d62785950092b05a4ec1206e 100644 (file)
@@ -664,7 +664,7 @@ static int io_init(struct ubi_device *ubi)
        ubi->peb_count  = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
        ubi->flash_size = ubi->mtd->size;
 
-       if (ubi->mtd->block_isbad && ubi->mtd->block_markbad)
+       if (mtd_can_have_bb(ubi->mtd))
                ubi->bad_allowed = 1;
 
        if (ubi->mtd->type == MTD_NORFLASH) {
index 089370758fc9ca50bc355bff83c9a07dae3ed1ba..7e35755f69311eb4ccadcf54a115b9ba8d5a044f 100644 (file)
@@ -440,6 +440,8 @@ static inline void mtd_resume(struct mtd_info *mtd)
 
 static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
 {
+       if (!mtd->block_isbad)
+               return -EOPNOTSUPP;
        return mtd->block_isbad(mtd, ofs);
 }
 
@@ -483,6 +485,11 @@ static inline int mtd_has_oob(const struct mtd_info *mtd)
        return mtd->read_oob && mtd->write_oob;
 }
 
+static inline int mtd_can_have_bb(const struct mtd_info *mtd)
+{
+       return !!mtd->block_isbad;
+}
+
        /* Kernel-side ioctl definitions */
 
 struct mtd_partition;