mtd: introduce mtd_read_oob interface
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 23 Dec 2011 16:27:05 +0000 (18:27 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:25:23 +0000 (18:25 +0000)
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
14 files changed:
drivers/mtd/inftlcore.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdpart.c
drivers/mtd/mtdswap.c
drivers/mtd/nand/nand_bbt.c
drivers/mtd/nftlcore.c
drivers/mtd/sm_ftl.c
drivers/mtd/ssfdc.c
drivers/mtd/tests/mtd_oobtest.c
drivers/mtd/tests/mtd_readtest.c
drivers/staging/spectra/lld_mtd.c
fs/jffs2/wbuf.c
include/linux/mtd/mtd.h

index 0b038bed7b9cd519857d4360615989776c51a3f9..07646e1273e2f6004dcec08126f9e23c47f68871 100644 (file)
@@ -158,7 +158,7 @@ int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
        ops.oobbuf = buf;
        ops.datbuf = NULL;
 
-       res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+       res = mtd_read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
        *retlen = ops.oobretlen;
        return res;
 }
index 922da31d2c6b5e8ef01e4ac255e10c0d2705fdfc..e74f570a7b932941231f691dcbc3fa6543223e6a 100644 (file)
@@ -227,7 +227,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count,
                        ops.oobbuf = NULL;
                        ops.len = len;
 
-                       ret = mtd->read_oob(mtd, *ppos, &ops);
+                       ret = mtd_read_oob(mtd, *ppos, &ops);
                        retlen = ops.retlen;
                        break;
                }
@@ -471,7 +471,7 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
                return -ENOMEM;
 
        start &= ~((uint64_t)mtd->writesize - 1);
-       ret = mtd->read_oob(mtd, start, &ops);
+       ret = mtd_read_oob(mtd, start, &ops);
 
        if (put_user(ops.oobretlen, retp))
                ret = -EFAULT;
index 45215501c4c7e6a7138e04f8c4553bccb4dbb944..cf35642e5f495da8b566f9c6f6fb72a32176f0c0 100644 (file)
@@ -273,7 +273,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
                if (from + devops.len > subdev->size)
                        devops.len = subdev->size - from;
 
-               err = subdev->read_oob(subdev, from, &devops);
+               err = mtd_read_oob(subdev, from, &devops);
                ops->retlen += devops.retlen;
                ops->oobretlen += devops.oobretlen;
 
index 9ed58f7d7466e6089787f9d384c9a4c8fb2b6eac..6fdc74ef19c1799238a8f40d19fa505d0f68e0f7 100644 (file)
@@ -138,7 +138,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
                        return -EINVAL;
        }
 
-       res = part->master->read_oob(part->master, from + part->offset, ops);
+       res = mtd_read_oob(part->master, from + part->offset, ops);
        if (unlikely(res)) {
                if (mtd_is_bitflip(res))
                        mtd->ecc_stats.corrected++;
index 6ff823e29c0ce3e64dab1c7c64e81eed3938033c..0f0ab18d4405cac4e5b400fd7c9583a60fbfbedf 100644 (file)
@@ -312,7 +312,7 @@ static int mtdswap_handle_write_error(struct mtdswap_dev *d, struct swap_eb *eb)
 static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from,
                        struct mtd_oob_ops *ops)
 {
-       int ret = d->mtd->read_oob(d->mtd, from, ops);
+       int ret = mtd_read_oob(d->mtd, from, ops);
 
        if (mtd_is_bitflip(ret))
                return ret;
@@ -955,7 +955,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d,
 
                pos = base;
                for (i = 0; i < mtd_pages; i++) {
-                       ret = mtd->read_oob(mtd, pos, &ops);
+                       ret = mtd_read_oob(mtd, pos, &ops);
                        if (ret)
                                goto error;
 
index 1bcd6bc6798c7f6cbad5a2ecdc6956996bcb3223..fcab50e80b9067d5bd7913b10992e48d7f20c01a 100644 (file)
@@ -317,7 +317,7 @@ static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
                ops.len = min(len, (size_t)mtd->writesize);
                ops.oobbuf = buf + ops.len;
 
-               res = mtd->read_oob(mtd, offs, &ops);
+               res = mtd_read_oob(mtd, offs, &ops);
 
                if (res)
                        return res;
@@ -434,7 +434,7 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
                 * Read the full oob until read_oob is fixed to handle single
                 * byte reads for 16 bit buswidth.
                 */
-               ret = mtd->read_oob(mtd, offs, &ops);
+               ret = mtd_read_oob(mtd, offs, &ops);
                /* Ignore ECC errors when checking for BBM */
                if (ret && !mtd_is_bitflip_or_eccerr(ret))
                        return ret;
@@ -769,7 +769,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
                        /* Read oob data */
                        ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
                        ops.oobbuf = &buf[len];
-                       res = mtd->read_oob(mtd, to + mtd->writesize, &ops);
+                       res = mtd_read_oob(mtd, to + mtd->writesize, &ops);
                        if (res < 0 || ops.oobretlen != ops.ooblen)
                                goto outerr;
 
index 1a9d9c1d3a74d9e63d4efd6c820f9416df4c6441..7497f5efc26b08683507b241114f230a6ccc0183 100644 (file)
@@ -153,7 +153,7 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
        ops.oobbuf = buf;
        ops.datbuf = NULL;
 
-       res = mtd->read_oob(mtd, offs & ~mask, &ops);
+       res = mtd_read_oob(mtd, offs & ~mask, &ops);
        *retlen = ops.oobretlen;
        return res;
 }
index 2f1acb1ab5e85a3ef12ac203c1fb26cd95579eab..748aa441669113efdca7b94f16e2acf117349941 100644 (file)
@@ -278,7 +278,7 @@ again:
 
        /* Unfortunately, oob read will _always_ succeed,
                despite card removal..... */
-       ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
+       ret = mtd_read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
 
        /* Test for unknown errors */
        if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) {
index 293e22a5710f5c43c5a8394d5303e7674db393a3..0e6881338357e5ab565d4412aa5587b25f127e08 100644 (file)
@@ -175,7 +175,7 @@ static int read_raw_oob(struct mtd_info *mtd, loff_t offs, uint8_t *buf)
        ops.oobbuf = buf;
        ops.datbuf = NULL;
 
-       ret = mtd->read_oob(mtd, offs, &ops);
+       ret = mtd_read_oob(mtd, offs, &ops);
        if (ret < 0 || ops.oobretlen != OOB_SIZE)
                return -1;
 
index 7d52854c16ddbf7b11d8ea69751edb84b854a855..962d27a64e64df9cae29e3a344bd142cf2ff5540 100644 (file)
@@ -192,7 +192,7 @@ static int verify_eraseblock(int ebnum)
                ops.ooboffs   = use_offset;
                ops.datbuf    = NULL;
                ops.oobbuf    = readbuf;
-               err = mtd->read_oob(mtd, addr, &ops);
+               err = mtd_read_oob(mtd, addr, &ops);
                if (err || ops.oobretlen != use_len) {
                        printk(PRINT_PREF "error: readoob failed at %#llx\n",
                               (long long)addr);
@@ -219,7 +219,7 @@ static int verify_eraseblock(int ebnum)
                        ops.ooboffs   = 0;
                        ops.datbuf    = NULL;
                        ops.oobbuf    = readbuf;
-                       err = mtd->read_oob(mtd, addr, &ops);
+                       err = mtd_read_oob(mtd, addr, &ops);
                        if (err || ops.oobretlen != mtd->ecclayout->oobavail) {
                                printk(PRINT_PREF "error: readoob failed at "
                                       "%#llx\n", (long long)addr);
@@ -284,7 +284,7 @@ static int verify_eraseblock_in_one_go(int ebnum)
        ops.ooboffs   = 0;
        ops.datbuf    = NULL;
        ops.oobbuf    = readbuf;
-       err = mtd->read_oob(mtd, addr, &ops);
+       err = mtd_read_oob(mtd, addr, &ops);
        if (err || ops.oobretlen != len) {
                printk(PRINT_PREF "error: readoob failed at %#llx\n",
                       (long long)addr);
@@ -544,7 +544,7 @@ static int __init mtd_oobtest_init(void)
        ops.oobbuf    = readbuf;
        printk(PRINT_PREF "attempting to start read past end of OOB\n");
        printk(PRINT_PREF "an error is expected...\n");
-       err = mtd->read_oob(mtd, addr0, &ops);
+       err = mtd_read_oob(mtd, addr0, &ops);
        if (err) {
                printk(PRINT_PREF "error occurred as expected\n");
                err = 0;
@@ -588,7 +588,7 @@ static int __init mtd_oobtest_init(void)
                ops.oobbuf    = readbuf;
                printk(PRINT_PREF "attempting to read past end of device\n");
                printk(PRINT_PREF "an error is expected...\n");
-               err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops);
+               err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops);
                if (err) {
                        printk(PRINT_PREF "error occurred as expected\n");
                        err = 0;
@@ -632,7 +632,7 @@ static int __init mtd_oobtest_init(void)
                ops.oobbuf    = readbuf;
                printk(PRINT_PREF "attempting to read past end of device\n");
                printk(PRINT_PREF "an error is expected...\n");
-               err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops);
+               err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops);
                if (err) {
                        printk(PRINT_PREF "error occurred as expected\n");
                        err = 0;
@@ -698,7 +698,7 @@ static int __init mtd_oobtest_init(void)
                ops.ooboffs   = 0;
                ops.datbuf    = NULL;
                ops.oobbuf    = readbuf;
-               err = mtd->read_oob(mtd, addr, &ops);
+               err = mtd_read_oob(mtd, addr, &ops);
                if (err)
                        goto out;
                if (memcmp(readbuf, writebuf, mtd->ecclayout->oobavail * 2)) {
index 0c58d2976c766cddbc106e9de7386090f4b4cac2..5eaeada8428418abf26bac3b3e6db116fedd5fc1 100644 (file)
@@ -74,7 +74,7 @@ static int read_eraseblock_by_page(int ebnum)
                        ops.ooboffs   = 0;
                        ops.datbuf    = NULL;
                        ops.oobbuf    = oobbuf;
-                       ret = mtd->read_oob(mtd, addr, &ops);
+                       ret = mtd_read_oob(mtd, addr, &ops);
                        if ((ret && !mtd_is_bitflip(ret)) ||
                                        ops.oobretlen != mtd->oobsize) {
                                printk(PRINT_PREF "error: read oob failed at "
index 2eb032131960e2acf714fec6572dba4cb8c25794..ed8e5f06708739e9ae5243b3359cd8dc5ab49c8f 100644 (file)
@@ -351,9 +351,9 @@ u16 mtd_Read_Page_Main_Spare(u8 *read_data, u32 Block,
                ops.ooblen = BTSIG_BYTES;
                ops.ooboffs = 0;
 
-               ret = spectra_mtd->read_oob(spectra_mtd,
-                                           (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
-                                           &ops);
+               ret = mtd_read_oob(spectra_mtd,
+                                  (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
+                                  &ops);
                if (ret) {
                        printk(KERN_ERR "%s failed %d\n", __func__, ret);
                        return FAIL;
@@ -484,9 +484,9 @@ u16 mtd_Read_Page_Spare(u8 *read_data, u32 Block,
                ops.ooblen = BTSIG_BYTES;
                ops.ooboffs = 0;
 
-               ret = spectra_mtd->read_oob(spectra_mtd,
-                                           (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
-                                           &ops);
+               ret = mtd_read_oob(spectra_mtd,
+                                  (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
+                                  &ops);
                if (ret) {
                        printk(KERN_ERR "%s failed %d\n", __func__, ret);
                        return FAIL;
index 3ea2f8db93587760f323119c38e071bcd8de76c0..efc0cb370306c88c366f751f1cdf33b2984044d9 100644 (file)
@@ -1032,7 +1032,7 @@ int jffs2_check_oob_empty(struct jffs2_sb_info *c,
        ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
        ops.datbuf = NULL;
 
-       ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops);
+       ret = mtd_read_oob(c->mtd, jeb->offset, &ops);
        if (ret || ops.oobretlen != ops.ooblen) {
                printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd"
                                " bytes, read %zd bytes, error %d\n",
@@ -1075,7 +1075,7 @@ int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c,
        ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
        ops.datbuf = NULL;
 
-       ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops);
+       ret = mtd_read_oob(c->mtd, jeb->offset, &ops);
        if (ret || ops.oobretlen != ops.ooblen) {
                printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd"
                                " bytes, read %zd bytes, error %d\n",
index 2fb83cd3d264bbb13bce97075d3b6059c6c33f4d..0db8d87ce4518f666b7009a858f5dfa19dcd47c9 100644 (file)
@@ -188,6 +188,8 @@ struct mtd_info {
                      size_t *retlen, const u_char *buf);
        int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
                            size_t *retlen, const u_char *buf);
+       int (*read_oob) (struct mtd_info *mtd, loff_t from,
+                        struct mtd_oob_ops *ops);
 
        /* Backing device capabilities for this device
         * - provides mmap capabilities
@@ -195,8 +197,6 @@ struct mtd_info {
        struct backing_dev_info *backing_dev_info;
 
 
-       int (*read_oob) (struct mtd_info *mtd, loff_t from,
-                        struct mtd_oob_ops *ops);
        int (*write_oob) (struct mtd_info *mtd, loff_t to,
                         struct mtd_oob_ops *ops);
 
@@ -320,6 +320,12 @@ static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
        return mtd->panic_write(mtd, to, len, retlen, buf);
 }
 
+static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from,
+                              struct mtd_oob_ops *ops)
+{
+       return mtd->read_oob(mtd, from, ops);
+}
+
 static inline struct mtd_info *dev_to_mtd(struct device *dev)
 {
        return dev ? dev_get_drvdata(dev) : NULL;