mtd: do not use mtd->read_*_prot_reg directly
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 29 Dec 2011 08:06:32 +0000 (10:06 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:26:16 +0000 (18:26 +0000)
Instead, call 'mtd_read_*_prot_info()' and check for -EOPNOTSUPP.

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 49340dc1b10749dd0bff9300c1f013368d1dfe24..4e8e5fbc1e132c4934e95f8504f5d1eab7db5d84 100644 (file)
@@ -366,20 +366,22 @@ static void mtdchar_erase_callback (struct erase_info *instr)
 static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
 {
        struct mtd_info *mtd = mfi->mtd;
+       size_t retlen;
        int ret = 0;
 
+       /*
+        * Make a fake call to mtd_read_fact_prot_reg() to check if OTP
+        * operations are supported.
+        */
+       if (mtd_read_fact_prot_reg(mtd, -1, -1, &retlen, NULL) == -EOPNOTSUPP)
+               return -EOPNOTSUPP;
+
        switch (mode) {
        case MTD_OTP_FACTORY:
-               if (!mtd->read_fact_prot_reg)
-                       ret = -EOPNOTSUPP;
-               else
-                       mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
+               mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
                break;
        case MTD_OTP_USER:
-               if (!mtd->read_fact_prot_reg)
-                       ret = -EOPNOTSUPP;
-               else
-                       mfi->mode = MTD_FILE_MODE_OTP_USER;
+               mfi->mode = MTD_FILE_MODE_OTP_USER;
                break;
        default:
                ret = -EINVAL;
index 7122efdc6d99ca83118219b6ee63d09032c8635e..e488cf9109148eebef66686c7ad450ddf0421628 100644 (file)
@@ -352,6 +352,8 @@ static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
                                         u_char *buf)
 {
        *retlen = 0;
+       if (!mtd->read_fact_prot_reg)
+               return -EOPNOTSUPP;
        return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf);
 }
 
@@ -369,6 +371,8 @@ static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
                                         u_char *buf)
 {
        *retlen = 0;
+       if (!mtd->read_user_prot_reg)
+               return -EOPNOTSUPP;
        return mtd->read_user_prot_reg(mtd, from, len, retlen, buf);
 }