diff options
author | Vitaly Wool <vwool@ru.mvista.com> | 2006-11-03 10:20:38 -0500 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2006-11-28 17:39:03 -0500 |
commit | 7014568bad55c20b7ee4f439d78c9e875912d51f (patch) | |
tree | 1b558ef8d77d31925cc396ed69d8f785615cf09f /drivers/mtd/mtdchar.c | |
parent | 191876729901d0c8dab8a331f9a1e4b73a56457b (diff) |
[MTD] [NAND] remove len/ooblen confusion.
As was discussed between Ricard Wanderlöf, David Woodhouse, Artem
Bityutskiy and me, the current API for reading/writing OOB is confusing.
The thing that introduces confusion is the need to specify ops.len
together with ops.ooblen for reads/writes that concern only OOB not data
area. So, ops.len is overloaded: when ops.datbuf != NULL it serves to
specify the length of the data read, and when ops.datbuf == NULL, it
serves to specify the full OOB read length.
The patch inlined below is the slightly updated version of the previous
patch serving the same purpose, but with the new Artem's comments taken
into account.
Artem, BTW, thanks a lot for your valuable input!
Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r-- | drivers/mtd/mtdchar.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 866c8e0d57e4..07618f51d969 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -499,13 +499,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
499 | if (ret) | 499 | if (ret) |
500 | return ret; | 500 | return ret; |
501 | 501 | ||
502 | ops.len = buf.length; | ||
503 | ops.ooblen = buf.length; | 502 | ops.ooblen = buf.length; |
504 | ops.ooboffs = buf.start & (mtd->oobsize - 1); | 503 | ops.ooboffs = buf.start & (mtd->oobsize - 1); |
505 | ops.datbuf = NULL; | 504 | ops.datbuf = NULL; |
506 | ops.mode = MTD_OOB_PLACE; | 505 | ops.mode = MTD_OOB_PLACE; |
507 | 506 | ||
508 | if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs)) | 507 | if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) |
509 | return -EINVAL; | 508 | return -EINVAL; |
510 | 509 | ||
511 | ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); | 510 | ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); |
@@ -520,7 +519,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
520 | buf.start &= ~(mtd->oobsize - 1); | 519 | buf.start &= ~(mtd->oobsize - 1); |
521 | ret = mtd->write_oob(mtd, buf.start, &ops); | 520 | ret = mtd->write_oob(mtd, buf.start, &ops); |
522 | 521 | ||
523 | if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen, | 522 | if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen, |
524 | sizeof(uint32_t))) | 523 | sizeof(uint32_t))) |
525 | ret = -EFAULT; | 524 | ret = -EFAULT; |
526 | 525 | ||
@@ -548,7 +547,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
548 | if (ret) | 547 | if (ret) |
549 | return ret; | 548 | return ret; |
550 | 549 | ||
551 | ops.len = buf.length; | ||
552 | ops.ooblen = buf.length; | 550 | ops.ooblen = buf.length; |
553 | ops.ooboffs = buf.start & (mtd->oobsize - 1); | 551 | ops.ooboffs = buf.start & (mtd->oobsize - 1); |
554 | ops.datbuf = NULL; | 552 | ops.datbuf = NULL; |
@@ -564,10 +562,10 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
564 | buf.start &= ~(mtd->oobsize - 1); | 562 | buf.start &= ~(mtd->oobsize - 1); |
565 | ret = mtd->read_oob(mtd, buf.start, &ops); | 563 | ret = mtd->read_oob(mtd, buf.start, &ops); |
566 | 564 | ||
567 | if (put_user(ops.retlen, (uint32_t __user *)argp)) | 565 | if (put_user(ops.oobretlen, (uint32_t __user *)argp)) |
568 | ret = -EFAULT; | 566 | ret = -EFAULT; |
569 | else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf, | 567 | else if (ops.oobretlen && copy_to_user(buf.ptr, ops.oobbuf, |
570 | ops.retlen)) | 568 | ops.oobretlen)) |
571 | ret = -EFAULT; | 569 | ret = -EFAULT; |
572 | 570 | ||
573 | kfree(ops.oobbuf); | 571 | kfree(ops.oobbuf); |