mtd: do not use mtd->read_oob directly

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Jan 9 13:59:16 EST 2012


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=dac2639f9833e858139d7e07f6ee45fb2191a9f2
Commit:     dac2639f9833e858139d7e07f6ee45fb2191a9f2
Parent:     016c1291ce70a22f15f666441a4fd2f0b450375b
Author:     Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
AuthorDate: Wed Dec 28 17:50:34 2011 +0200
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Mon Jan 9 18:26:14 2012 +0000

    mtd: do not use mtd->read_oob directly
    
    Instead of checking whether 'mtd->read_oob' is defined, just call
    'mtd_read_oob()' and handle the '-EOPNOTSUPP' error which will be returned
    if the function is undefined.
    
    Additionally, make 'mtd_write_oob()' return '-EOPNOTSUPP' if the function
    is undefined.
    
    Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/mtdchar.c   |    9 ++-------
 include/linux/mtd/mtd.h |    4 ++++
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 55f0961..287ff0d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -452,13 +452,8 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
 	if (length > 4096)
 		return -EINVAL;
 
-	if (!mtd->read_oob)
-		ret = -EOPNOTSUPP;
-	else
-		ret = access_ok(VERIFY_WRITE, ptr,
-				length) ? 0 : -EFAULT;
-	if (ret)
-		return ret;
+	if (!access_ok(VERIFY_WRITE, ptr, length))
+		return -EFAULT;
 
 	ops.ooblen = length;
 	ops.ooboffs = start & (mtd->writesize - 1);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index b729640..721a63f 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -320,6 +320,8 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from,
 			       struct mtd_oob_ops *ops)
 {
 	ops->retlen = ops->oobretlen = 0;
+	if (!mtd->read_oob)
+		return -EOPNOTSUPP;
 	return mtd->read_oob(mtd, from, ops);
 }
 
@@ -327,6 +329,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
 				struct mtd_oob_ops *ops)
 {
 	ops->retlen = ops->oobretlen = 0;
+	if (!mtd->write_oob)
+		return -EOPNOTSUPP;
 	return mtd->write_oob(mtd, to, ops);
 }
 



More information about the linux-mtd-cvs mailing list