mtd: introduce mtd_erase interface
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 23 Dec 2011 13:25:39 +0000 (15:25 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:25:11 +0000 (18:25 +0000)
This patch is part of a patch-set which changes the MTD interface
from 'mtd->func()' form to 'mtd_func()' form. We need this because
we want to add common code to to all drivers in the mtd core level,
which is impossible with the current interface when MTD clients
call driver functions like 'read()' or 'write()' directly.

At this point we just introduce a new inline wrapper function, but
later some of them are expected to gain more code. E.g., the input
parameters check should be moved to the wrappers rather than be
duplicated at many drivers.

This particular patch introduced the 'mtd_erase()' interface. The
following patches add all the other interfaces one by one.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
22 files changed:
drivers/mtd/ftl.c
drivers/mtd/inftlmount.c
drivers/mtd/mtdblock.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdoops.c
drivers/mtd/mtdpart.c
drivers/mtd/mtdswap.c
drivers/mtd/nftlmount.c
drivers/mtd/rfd_ftl.c
drivers/mtd/sm_ftl.c
drivers/mtd/tests/mtd_oobtest.c
drivers/mtd/tests/mtd_pagetest.c
drivers/mtd/tests/mtd_speedtest.c
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_subpagetest.c
drivers/mtd/tests/mtd_torturetest.c
drivers/mtd/ubi/io.c
drivers/staging/spectra/lld_mtd.c
fs/jffs2/erase.c
fs/logfs/dev_mtd.c
include/linux/mtd/mtd.h

index c7382bb686c679efef42dd5218cce645002512eb..a982889277c80fdb93980158f5460e15f7cdb50d 100644 (file)
@@ -355,7 +355,7 @@ static int erase_xfer(partition_t *part,
     erase->len = 1 << part->header.EraseUnitSize;
     erase->priv = (u_long)part;
 
-    ret = part->mbd.mtd->erase(part->mbd.mtd, erase);
+    ret = mtd_erase(part->mbd.mtd, erase);
 
     if (!ret)
            xfer->EraseCount++;
index 2ff601f816cebd12b4210b199e85fbcbdfb424cf..0d946f10a682f1b9123c8b25e9834bd9251b638d 100644 (file)
@@ -220,7 +220,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
                                 */
                                instr->addr = ip->Reserved0 * inftl->EraseSize;
                                instr->len = inftl->EraseSize;
-                               mtd->erase(mtd, instr);
+                               mtd_erase(mtd, instr);
                        }
                        if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
                                printk(KERN_WARNING "INFTL: Media Header "
@@ -393,7 +393,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
           mark only the failed block in the bbt. */
        for (physblock = 0; physblock < inftl->EraseSize;
             physblock += instr->len, instr->addr += instr->len) {
-               mtd->erase(inftl->mbd.mtd, instr);
+               mtd_erase(inftl->mbd.mtd, instr);
 
                if (instr->state == MTD_ERASE_FAILED) {
                        printk(KERN_WARNING "INFTL: error while formatting block %d\n",
index 7c1dc908a17475eeb1f610deb8f36505e5b2e439..9b01cb0266e49e745f5b1743f2ff0210e4de6132 100644 (file)
@@ -85,7 +85,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&wait_q, &wait);
 
-       ret = mtd->erase(mtd, &erase);
+       ret = mtd_erase(mtd, &erase);
        if (ret) {
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&wait_q, &wait);
index 00423cc858077b72043a843e6962594387f6c979..41d64ff4c2522958451e468e71b7cba2713919dd 100644 (file)
@@ -731,7 +731,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
                          wq_head is no longer there when the
                          callback routine tries to wake us up.
                        */
-                       ret = mtd->erase(mtd, erase);
+                       ret = mtd_erase(mtd, erase);
                        if (!ret) {
                                set_current_state(TASK_UNINTERRUPTIBLE);
                                add_wait_queue(&waitq, &wait);
index 6df4d4d4eb92bb585c9f0bc08815be208cda2d53..76123bd49314b929e9e9391d5fd0f639e45d84f0 100644 (file)
@@ -379,7 +379,7 @@ static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
         * FIXME: Allow INTERRUPTIBLE. Which means
         * not having the wait_queue head on the stack.
         */
-       err = mtd->erase(mtd, erase);
+       err = mtd_erase(mtd, erase);
        if (!err) {
                set_current_state(TASK_UNINTERRUPTIBLE);
                add_wait_queue(&waitq, &wait);
index f3cdce9a85a6602f2078ce1ffa67d095a26e4e7e..9b2d863231694cc9b56bed6bd8d42d18c25e82e6 100644 (file)
@@ -112,7 +112,7 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset)
        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&wait_q, &wait);
 
-       ret = mtd->erase(mtd, &erase);
+       ret = mtd_erase(mtd, &erase);
        if (ret) {
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&wait_q, &wait);
index a0bd2de4752baa3981b09a31b1efb0cc5f7b4a8b..d318fee28595f572235348d81051e2bcbbac5611 100644 (file)
@@ -257,7 +257,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
        if (instr->addr >= mtd->size)
                return -EINVAL;
        instr->addr += part->offset;
-       ret = part->master->erase(part->master, instr);
+       ret = mtd_erase(part->master, instr);
        if (ret) {
                if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
                        instr->fail_addr -= part->offset;
index bd9590c723e41fcbb7055cc4dc61f49f402e340d..4e12875a916cc08472d61b2a2bfa05c59098bc94 100644 (file)
@@ -567,7 +567,7 @@ retry:
        erase.len       = mtd->erasesize;
        erase.priv      = (u_long)&wq;
 
-       ret = mtd->erase(mtd, &erase);
+       ret = mtd_erase(mtd, &erase);
        if (ret) {
                if (retries++ < MTDSWAP_ERASE_RETRIES) {
                        dev_warn(d->dev,
index ac4092591aea035068e169900b099ca8121c2185..9164a56fb5c0fd0fa036f51a670e36be5eae7347 100644 (file)
@@ -326,7 +326,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
        instr->mtd = nftl->mbd.mtd;
        instr->addr = block * nftl->EraseSize;
        instr->len = nftl->EraseSize;
-       mtd->erase(mtd, instr);
+       mtd_erase(mtd, instr);
 
        if (instr->state == MTD_ERASE_FAILED) {
                printk("Error while formatting block %d\n", block);
index 73ae217a4252a1b386c7c9b3b820dece4c3e65bd..39de8727a524b154fe8f2df8df52cb3d4aac07d2 100644 (file)
@@ -342,7 +342,7 @@ static int erase_block(struct partition *part, int block)
        part->blocks[block].state = BLOCK_ERASING;
        part->blocks[block].free_sectors = 0;
 
-       rc = part->mbd.mtd->erase(part->mbd.mtd, erase);
+       rc = mtd_erase(part->mbd.mtd, erase);
 
        if (rc) {
                printk(KERN_ERR PREFIX "erase of region %llx,%llx on '%s' "
index 1c9f307ae0a177c6eca1aabf1bb68ed37ce0aa0e..2f1acb1ab5e85a3ef12ac203c1fb26cd95579eab 100644 (file)
@@ -479,7 +479,7 @@ static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
                return -EIO;
        }
 
-       if (mtd->erase(mtd, &erase)) {
+       if (mtd_erase(mtd, &erase)) {
                sm_printk("erase of block %d in zone %d failed",
                                                        block, zone_num);
                goto error;
index 933f7e5f32d301a90f7256750b03c8a1542a9609..7d52854c16ddbf7b11d8ea69751edb84b854a855 100644 (file)
@@ -78,7 +78,7 @@ static int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
index afafb6935fd0870707d13f9b7ea12cfbbb69af56..271819fabb55f86f675e3077e7805325105016d5 100644 (file)
@@ -77,7 +77,7 @@ static int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
index 493b367bdd35211af2db7273d981398a938dd039..f67a65e21043b5654d49c20c2177459036f94ea2 100644 (file)
@@ -79,7 +79,7 @@ static int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
@@ -105,7 +105,7 @@ static int multiblock_erase(int ebnum, int blocks)
        ei.addr = addr;
        ei.len  = mtd->erasesize * blocks;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n",
                       err, ebnum, blocks);
index 811642fea6b48df641a3c203b05f4b57b184c990..a204a9f905248042c22cafc461bcec3f62d94923 100644 (file)
@@ -112,7 +112,7 @@ static int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (unlikely(err)) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
index 1a05bfac4eeee5f6f9406b469ab27a74760c3cc8..16d0c05024d723a61e6f93360029dd5718dfc751 100644 (file)
@@ -80,7 +80,7 @@ static int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
index 03ab649a6964292f50f40f9073c45ae097a47b8e..102c79b7ac6619e62c1b449b99856d377b9a5ce0 100644 (file)
@@ -105,7 +105,7 @@ static inline int erase_eraseblock(int ebnum)
        ei.addr = addr;
        ei.len  = mtd->erasesize;
 
-       err = mtd->erase(mtd, &ei);
+       err = mtd_erase(mtd, &ei);
        if (err) {
                printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
                return err;
index f20b6f22f240378ce6386ee8c4e59d25f81cb3de..b6c8959e6c7eb6b32e85d7ec17635a443f29ab22 100644 (file)
@@ -361,7 +361,7 @@ retry:
        ei.callback = erase_callback;
        ei.priv     = (unsigned long)&wq;
 
-       err = ubi->mtd->erase(ubi->mtd, &ei);
+       err = mtd_erase(ubi->mtd, &ei);
        if (err) {
                if (retries++ < UBI_IO_RETRIES) {
                        dbg_io("error %d while erasing PEB %d, retry",
index a9c309a167c2d43f71c79b670a4e00d6e76b567f..d638fafab649320c82363ad4e8f3ad23af244335 100644 (file)
@@ -188,7 +188,7 @@ u16 mtd_Erase_Block(u32 block_add)
        erase.len = spectra_mtd->erasesize;
        erase.priv = (unsigned long)&comp;
 
-       ret = spectra_mtd->erase(spectra_mtd, &erase);
+       ret = mtd_erase(spectra_mtd, &erase);
        if (!ret) {
                wait_for_completion(&comp);
                if (erase.state != MTD_ERASE_DONE)
index e513f1913c1522a8e9e8dbc4f501a4804507d182..540e8eca1b49d0785fd479657a232dbbb4bdb9c4 100644 (file)
@@ -74,7 +74,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
        ((struct erase_priv_struct *)instr->priv)->jeb = jeb;
        ((struct erase_priv_struct *)instr->priv)->c = c;
 
-       ret = c->mtd->erase(c->mtd, instr);
+       ret = mtd_erase(c->mtd, instr);
        if (!ret)
                return;
 
index eb423ebcf53838d31251c911d6a017eed259629d..046362894352047bbf48671281cd048d459d4ed9 100644 (file)
@@ -105,7 +105,7 @@ static int logfs_mtd_erase(struct super_block *sb, loff_t ofs, size_t len,
        ei.len = len;
        ei.callback = logfs_erase_callback;
        ei.priv = (long)&complete;
-       ret = mtd->erase(mtd, &ei);
+       ret = mtd_erase(mtd, &ei);
        if (ret)
                return -EIO;
 
index 9f5b312af7838d5275ff9611030da3861ec2d612..201bad5570478e8de1f3ee26cc24b80dcef0e912 100644 (file)
@@ -171,11 +171,8 @@ struct mtd_info {
        struct mtd_erase_region_info *eraseregions;
 
        /*
-        * Erase is an asynchronous operation.  Device drivers are supposed
-        * to call instr->callback() whenever the operation completes, even
-        * if it completes with a failure.
-        * Callers are supposed to pass a callback function and wait for it
-        * to be called before writing to the block.
+        * Do not call via these pointers, use corresponding mtd_*()
+        * wrappers instead.
         */
        int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
 
@@ -274,6 +271,18 @@ struct mtd_info {
        void (*put_device) (struct mtd_info *mtd);
 };
 
+/*
+ * Erase is an asynchronous operation.  Device drivers are supposed
+ * to call instr->callback() whenever the operation completes, even
+ * if it completes with a failure.
+ * Callers are supposed to pass a callback function and wait for it
+ * to be called before writing to the block.
+ */
+static inline int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+       return mtd->erase(mtd, instr);
+}
+
 static inline struct mtd_info *dev_to_mtd(struct device *dev)
 {
        return dev ? dev_get_drvdata(dev) : NULL;