mtd: do not use mtd->get_*_prot_info 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=87e858a97e8a7010aedc01db7cd31cc7c02b0b6a
Commit:     87e858a97e8a7010aedc01db7cd31cc7c02b0b6a
Parent:     dac2639f9833e858139d7e07f6ee45fb2191a9f2
Author:     Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
AuthorDate: Wed Dec 28 18:47:46 2011 +0200
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Mon Jan 9 18:26:15 2012 +0000

    mtd: do not use mtd->get_*_prot_info directly
    
    Instead, call 'mtd_get_*_prot_info()' and check for '-EOPNOTSUPP'. While
    on it, fix the return code from '-EOPNOTSUPP' to '-EINVAL' for the case
    when the mode parameter is invalid.
    
    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   |    8 +++-----
 include/linux/mtd/mtd.h |    4 ++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 287ff0d..49340dc 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -919,17 +919,15 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 		struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
 		if (!buf)
 			return -ENOMEM;
-		ret = -EOPNOTSUPP;
 		switch (mfi->mode) {
 		case MTD_FILE_MODE_OTP_FACTORY:
-			if (mtd->get_fact_prot_info)
-				ret = mtd_get_fact_prot_info(mtd, buf, 4096);
+			ret = mtd_get_fact_prot_info(mtd, buf, 4096);
 			break;
 		case MTD_FILE_MODE_OTP_USER:
-			if (mtd->get_user_prot_info)
-				ret = mtd_get_user_prot_info(mtd, buf, 4096);
+			ret = mtd_get_user_prot_info(mtd, buf, 4096);
 			break;
 		default:
+			ret = -EINVAL;
 			break;
 		}
 		if (ret >= 0) {
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 721a63f..7122efd 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -342,6 +342,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
 static inline int mtd_get_fact_prot_info(struct mtd_info *mtd,
 					 struct otp_info *buf, size_t len)
 {
+	if (!mtd->get_fact_prot_info)
+		return -EOPNOTSUPP;
 	return mtd->get_fact_prot_info(mtd, buf, len);
 }
 
@@ -357,6 +359,8 @@ static inline int mtd_get_user_prot_info(struct mtd_info *mtd,
 					 struct otp_info *buf,
 					 size_t len)
 {
+	if (!mtd->get_user_prot_info)
+		return -EOPNOTSUPP;
 	return mtd->get_user_prot_info(mtd, buf, len);
 }
 



More information about the linux-mtd-cvs mailing list