Commit fd2819bbc92fc98bed5d612e4acbe16b6326f6bf
Committed by
David Woodhouse
1 parent
7ae79d7ff1
Exists in
master
and in
20 other branches
mtd: introduce mtd_read_oob interface
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Showing 14 changed files with 37 additions and 31 deletions Side-by-side Diff
- 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
drivers/mtd/inftlcore.c
drivers/mtd/mtdchar.c
... | ... | @@ -227,7 +227,7 @@ |
227 | 227 | ops.oobbuf = NULL; |
228 | 228 | ops.len = len; |
229 | 229 | |
230 | - ret = mtd->read_oob(mtd, *ppos, &ops); | |
230 | + ret = mtd_read_oob(mtd, *ppos, &ops); | |
231 | 231 | retlen = ops.retlen; |
232 | 232 | break; |
233 | 233 | } |
... | ... | @@ -471,7 +471,7 @@ |
471 | 471 | return -ENOMEM; |
472 | 472 | |
473 | 473 | start &= ~((uint64_t)mtd->writesize - 1); |
474 | - ret = mtd->read_oob(mtd, start, &ops); | |
474 | + ret = mtd_read_oob(mtd, start, &ops); | |
475 | 475 | |
476 | 476 | if (put_user(ops.oobretlen, retp)) |
477 | 477 | ret = -EFAULT; |
drivers/mtd/mtdconcat.c
... | ... | @@ -273,7 +273,7 @@ |
273 | 273 | if (from + devops.len > subdev->size) |
274 | 274 | devops.len = subdev->size - from; |
275 | 275 | |
276 | - err = subdev->read_oob(subdev, from, &devops); | |
276 | + err = mtd_read_oob(subdev, from, &devops); | |
277 | 277 | ops->retlen += devops.retlen; |
278 | 278 | ops->oobretlen += devops.oobretlen; |
279 | 279 |
drivers/mtd/mtdpart.c
... | ... | @@ -138,7 +138,7 @@ |
138 | 138 | return -EINVAL; |
139 | 139 | } |
140 | 140 | |
141 | - res = part->master->read_oob(part->master, from + part->offset, ops); | |
141 | + res = mtd_read_oob(part->master, from + part->offset, ops); | |
142 | 142 | if (unlikely(res)) { |
143 | 143 | if (mtd_is_bitflip(res)) |
144 | 144 | mtd->ecc_stats.corrected++; |
drivers/mtd/mtdswap.c
... | ... | @@ -312,7 +312,7 @@ |
312 | 312 | static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from, |
313 | 313 | struct mtd_oob_ops *ops) |
314 | 314 | { |
315 | - int ret = d->mtd->read_oob(d->mtd, from, ops); | |
315 | + int ret = mtd_read_oob(d->mtd, from, ops); | |
316 | 316 | |
317 | 317 | if (mtd_is_bitflip(ret)) |
318 | 318 | return ret; |
... | ... | @@ -955,7 +955,7 @@ |
955 | 955 | |
956 | 956 | pos = base; |
957 | 957 | for (i = 0; i < mtd_pages; i++) { |
958 | - ret = mtd->read_oob(mtd, pos, &ops); | |
958 | + ret = mtd_read_oob(mtd, pos, &ops); | |
959 | 959 | if (ret) |
960 | 960 | goto error; |
961 | 961 |
drivers/mtd/nand/nand_bbt.c
... | ... | @@ -317,7 +317,7 @@ |
317 | 317 | ops.len = min(len, (size_t)mtd->writesize); |
318 | 318 | ops.oobbuf = buf + ops.len; |
319 | 319 | |
320 | - res = mtd->read_oob(mtd, offs, &ops); | |
320 | + res = mtd_read_oob(mtd, offs, &ops); | |
321 | 321 | |
322 | 322 | if (res) |
323 | 323 | return res; |
... | ... | @@ -434,7 +434,7 @@ |
434 | 434 | * Read the full oob until read_oob is fixed to handle single |
435 | 435 | * byte reads for 16 bit buswidth. |
436 | 436 | */ |
437 | - ret = mtd->read_oob(mtd, offs, &ops); | |
437 | + ret = mtd_read_oob(mtd, offs, &ops); | |
438 | 438 | /* Ignore ECC errors when checking for BBM */ |
439 | 439 | if (ret && !mtd_is_bitflip_or_eccerr(ret)) |
440 | 440 | return ret; |
... | ... | @@ -769,7 +769,7 @@ |
769 | 769 | /* Read oob data */ |
770 | 770 | ops.ooblen = (len >> this->page_shift) * mtd->oobsize; |
771 | 771 | ops.oobbuf = &buf[len]; |
772 | - res = mtd->read_oob(mtd, to + mtd->writesize, &ops); | |
772 | + res = mtd_read_oob(mtd, to + mtd->writesize, &ops); | |
773 | 773 | if (res < 0 || ops.oobretlen != ops.ooblen) |
774 | 774 | goto outerr; |
775 | 775 |
drivers/mtd/nftlcore.c
drivers/mtd/sm_ftl.c
... | ... | @@ -278,7 +278,7 @@ |
278 | 278 | |
279 | 279 | /* Unfortunately, oob read will _always_ succeed, |
280 | 280 | despite card removal..... */ |
281 | - ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); | |
281 | + ret = mtd_read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); | |
282 | 282 | |
283 | 283 | /* Test for unknown errors */ |
284 | 284 | if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) { |
drivers/mtd/ssfdc.c
drivers/mtd/tests/mtd_oobtest.c
... | ... | @@ -192,7 +192,7 @@ |
192 | 192 | ops.ooboffs = use_offset; |
193 | 193 | ops.datbuf = NULL; |
194 | 194 | ops.oobbuf = readbuf; |
195 | - err = mtd->read_oob(mtd, addr, &ops); | |
195 | + err = mtd_read_oob(mtd, addr, &ops); | |
196 | 196 | if (err || ops.oobretlen != use_len) { |
197 | 197 | printk(PRINT_PREF "error: readoob failed at %#llx\n", |
198 | 198 | (long long)addr); |
... | ... | @@ -219,7 +219,7 @@ |
219 | 219 | ops.ooboffs = 0; |
220 | 220 | ops.datbuf = NULL; |
221 | 221 | ops.oobbuf = readbuf; |
222 | - err = mtd->read_oob(mtd, addr, &ops); | |
222 | + err = mtd_read_oob(mtd, addr, &ops); | |
223 | 223 | if (err || ops.oobretlen != mtd->ecclayout->oobavail) { |
224 | 224 | printk(PRINT_PREF "error: readoob failed at " |
225 | 225 | "%#llx\n", (long long)addr); |
... | ... | @@ -284,7 +284,7 @@ |
284 | 284 | ops.ooboffs = 0; |
285 | 285 | ops.datbuf = NULL; |
286 | 286 | ops.oobbuf = readbuf; |
287 | - err = mtd->read_oob(mtd, addr, &ops); | |
287 | + err = mtd_read_oob(mtd, addr, &ops); | |
288 | 288 | if (err || ops.oobretlen != len) { |
289 | 289 | printk(PRINT_PREF "error: readoob failed at %#llx\n", |
290 | 290 | (long long)addr); |
... | ... | @@ -544,7 +544,7 @@ |
544 | 544 | ops.oobbuf = readbuf; |
545 | 545 | printk(PRINT_PREF "attempting to start read past end of OOB\n"); |
546 | 546 | printk(PRINT_PREF "an error is expected...\n"); |
547 | - err = mtd->read_oob(mtd, addr0, &ops); | |
547 | + err = mtd_read_oob(mtd, addr0, &ops); | |
548 | 548 | if (err) { |
549 | 549 | printk(PRINT_PREF "error occurred as expected\n"); |
550 | 550 | err = 0; |
... | ... | @@ -588,7 +588,7 @@ |
588 | 588 | ops.oobbuf = readbuf; |
589 | 589 | printk(PRINT_PREF "attempting to read past end of device\n"); |
590 | 590 | printk(PRINT_PREF "an error is expected...\n"); |
591 | - err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops); | |
591 | + err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops); | |
592 | 592 | if (err) { |
593 | 593 | printk(PRINT_PREF "error occurred as expected\n"); |
594 | 594 | err = 0; |
... | ... | @@ -632,7 +632,7 @@ |
632 | 632 | ops.oobbuf = readbuf; |
633 | 633 | printk(PRINT_PREF "attempting to read past end of device\n"); |
634 | 634 | printk(PRINT_PREF "an error is expected...\n"); |
635 | - err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops); | |
635 | + err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops); | |
636 | 636 | if (err) { |
637 | 637 | printk(PRINT_PREF "error occurred as expected\n"); |
638 | 638 | err = 0; |
... | ... | @@ -698,7 +698,7 @@ |
698 | 698 | ops.ooboffs = 0; |
699 | 699 | ops.datbuf = NULL; |
700 | 700 | ops.oobbuf = readbuf; |
701 | - err = mtd->read_oob(mtd, addr, &ops); | |
701 | + err = mtd_read_oob(mtd, addr, &ops); | |
702 | 702 | if (err) |
703 | 703 | goto out; |
704 | 704 | if (memcmp(readbuf, writebuf, mtd->ecclayout->oobavail * 2)) { |
drivers/mtd/tests/mtd_readtest.c
... | ... | @@ -74,7 +74,7 @@ |
74 | 74 | ops.ooboffs = 0; |
75 | 75 | ops.datbuf = NULL; |
76 | 76 | ops.oobbuf = oobbuf; |
77 | - ret = mtd->read_oob(mtd, addr, &ops); | |
77 | + ret = mtd_read_oob(mtd, addr, &ops); | |
78 | 78 | if ((ret && !mtd_is_bitflip(ret)) || |
79 | 79 | ops.oobretlen != mtd->oobsize) { |
80 | 80 | printk(PRINT_PREF "error: read oob failed at " |
drivers/staging/spectra/lld_mtd.c
... | ... | @@ -351,9 +351,9 @@ |
351 | 351 | ops.ooblen = BTSIG_BYTES; |
352 | 352 | ops.ooboffs = 0; |
353 | 353 | |
354 | - ret = spectra_mtd->read_oob(spectra_mtd, | |
355 | - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), | |
356 | - &ops); | |
354 | + ret = mtd_read_oob(spectra_mtd, | |
355 | + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), | |
356 | + &ops); | |
357 | 357 | if (ret) { |
358 | 358 | printk(KERN_ERR "%s failed %d\n", __func__, ret); |
359 | 359 | return FAIL; |
... | ... | @@ -484,9 +484,9 @@ |
484 | 484 | ops.ooblen = BTSIG_BYTES; |
485 | 485 | ops.ooboffs = 0; |
486 | 486 | |
487 | - ret = spectra_mtd->read_oob(spectra_mtd, | |
488 | - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), | |
489 | - &ops); | |
487 | + ret = mtd_read_oob(spectra_mtd, | |
488 | + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), | |
489 | + &ops); | |
490 | 490 | if (ret) { |
491 | 491 | printk(KERN_ERR "%s failed %d\n", __func__, ret); |
492 | 492 | return FAIL; |
fs/jffs2/wbuf.c
... | ... | @@ -1032,7 +1032,7 @@ |
1032 | 1032 | ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; |
1033 | 1033 | ops.datbuf = NULL; |
1034 | 1034 | |
1035 | - ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops); | |
1035 | + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); | |
1036 | 1036 | if (ret || ops.oobretlen != ops.ooblen) { |
1037 | 1037 | printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd" |
1038 | 1038 | " bytes, read %zd bytes, error %d\n", |
... | ... | @@ -1075,7 +1075,7 @@ |
1075 | 1075 | ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; |
1076 | 1076 | ops.datbuf = NULL; |
1077 | 1077 | |
1078 | - ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops); | |
1078 | + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); | |
1079 | 1079 | if (ret || ops.oobretlen != ops.ooblen) { |
1080 | 1080 | printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd" |
1081 | 1081 | " bytes, read %zd bytes, error %d\n", |
include/linux/mtd/mtd.h
... | ... | @@ -188,6 +188,8 @@ |
188 | 188 | size_t *retlen, const u_char *buf); |
189 | 189 | int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, |
190 | 190 | size_t *retlen, const u_char *buf); |
191 | + int (*read_oob) (struct mtd_info *mtd, loff_t from, | |
192 | + struct mtd_oob_ops *ops); | |
191 | 193 | |
192 | 194 | /* Backing device capabilities for this device |
193 | 195 | * - provides mmap capabilities |
... | ... | @@ -195,8 +197,6 @@ |
195 | 197 | struct backing_dev_info *backing_dev_info; |
196 | 198 | |
197 | 199 | |
198 | - int (*read_oob) (struct mtd_info *mtd, loff_t from, | |
199 | - struct mtd_oob_ops *ops); | |
200 | 200 | int (*write_oob) (struct mtd_info *mtd, loff_t to, |
201 | 201 | struct mtd_oob_ops *ops); |
202 | 202 | |
... | ... | @@ -318,6 +318,12 @@ |
318 | 318 | size_t *retlen, const u_char *buf) |
319 | 319 | { |
320 | 320 | return mtd->panic_write(mtd, to, len, retlen, buf); |
321 | +} | |
322 | + | |
323 | +static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, | |
324 | + struct mtd_oob_ops *ops) | |
325 | +{ | |
326 | + return mtd->read_oob(mtd, from, ops); | |
321 | 327 | } |
322 | 328 | |
323 | 329 | static inline struct mtd_info *dev_to_mtd(struct device *dev) |