[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>
This commit is contained in:
committed by
David Woodhouse
parent
1918767299
commit
7014568bad
@@ -499,13 +499,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ops.len = buf.length;
|
||||
ops.ooblen = buf.length;
|
||||
ops.ooboffs = buf.start & (mtd->oobsize - 1);
|
||||
ops.datbuf = NULL;
|
||||
ops.mode = MTD_OOB_PLACE;
|
||||
|
||||
if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs))
|
||||
if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
|
||||
return -EINVAL;
|
||||
|
||||
ops.oobbuf = kmalloc(buf.length, GFP_KERNEL);
|
||||
@@ -520,7 +519,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
|
||||
buf.start &= ~(mtd->oobsize - 1);
|
||||
ret = mtd->write_oob(mtd, buf.start, &ops);
|
||||
|
||||
if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen,
|
||||
if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen,
|
||||
sizeof(uint32_t)))
|
||||
ret = -EFAULT;
|
||||
|
||||
@@ -548,7 +547,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ops.len = buf.length;
|
||||
ops.ooblen = buf.length;
|
||||
ops.ooboffs = buf.start & (mtd->oobsize - 1);
|
||||
ops.datbuf = NULL;
|
||||
@@ -564,10 +562,10 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
|
||||
buf.start &= ~(mtd->oobsize - 1);
|
||||
ret = mtd->read_oob(mtd, buf.start, &ops);
|
||||
|
||||
if (put_user(ops.retlen, (uint32_t __user *)argp))
|
||||
if (put_user(ops.oobretlen, (uint32_t __user *)argp))
|
||||
ret = -EFAULT;
|
||||
else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf,
|
||||
ops.retlen))
|
||||
else if (ops.oobretlen && copy_to_user(buf.ptr, ops.oobbuf,
|
||||
ops.oobretlen))
|
||||
ret = -EFAULT;
|
||||
|
||||
kfree(ops.oobbuf);
|
||||
|
Reference in New Issue
Block a user