mtd: do not use mtd->get_*_prot_info directly
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 28 Dec 2011 16:47:46 +0000 (18:47 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:26:15 +0000 (18:26 +0000)
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@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdchar.c
include/linux/mtd/mtd.h

index 287ff0d35848101b4e438310edb37092a0b768a5..49340dc1b10749dd0bff9300c1f013368d1dfe24 100644 (file)
@@ -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) {
index 721a63ffeb96e17e461ec5df3f7fe8222c71a4d0..7122efdc6d99ca83118219b6ee63d09032c8635e 100644 (file)
@@ -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);
 }