mtd: do not use mtd->read_*_prot_reg 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=b6de3d6cb63427178c4f1df88b81d1ceee637e6f
Commit: b6de3d6cb63427178c4f1df88b81d1ceee637e6f
Parent: 87e858a97e8a7010aedc01db7cd31cc7c02b0b6a
Author: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
AuthorDate: Thu Dec 29 10:06:32 2011 +0200
Committer: David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Mon Jan 9 18:26:16 2012 +0000
mtd: do not use mtd->read_*_prot_reg directly
Instead, call 'mtd_read_*_prot_info()' and check for -EOPNOTSUPP.
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 | 18 ++++++++++--------
include/linux/mtd/mtd.h | 4 ++++
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 49340dc..4e8e5fb 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -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;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 7122efd..e488cf9 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -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);
}
More information about the linux-mtd-cvs
mailing list