aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/mtdchar.c18
-rw-r--r--include/linux/mtd/mtd.h4
2 files changed, 14 insertions, 8 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 49340dc1b107..4e8e5fbc1e13 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -366,20 +366,22 @@ static void mtdchar_erase_callback (struct erase_info *instr)
366static int otp_select_filemode(struct mtd_file_info *mfi, int mode) 366static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
367{ 367{
368 struct mtd_info *mtd = mfi->mtd; 368 struct mtd_info *mtd = mfi->mtd;
369 size_t retlen;
369 int ret = 0; 370 int ret = 0;
370 371
372 /*
373 * Make a fake call to mtd_read_fact_prot_reg() to check if OTP
374 * operations are supported.
375 */
376 if (mtd_read_fact_prot_reg(mtd, -1, -1, &retlen, NULL) == -EOPNOTSUPP)
377 return -EOPNOTSUPP;
378
371 switch (mode) { 379 switch (mode) {
372 case MTD_OTP_FACTORY: 380 case MTD_OTP_FACTORY:
373 if (!mtd->read_fact_prot_reg) 381 mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
374 ret = -EOPNOTSUPP;
375 else
376 mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
377 break; 382 break;
378 case MTD_OTP_USER: 383 case MTD_OTP_USER:
379 if (!mtd->read_fact_prot_reg) 384 mfi->mode = MTD_FILE_MODE_OTP_USER;
380 ret = -EOPNOTSUPP;
381 else
382 mfi->mode = MTD_FILE_MODE_OTP_USER;
383 break; 385 break;
384 default: 386 default:
385 ret = -EINVAL; 387 ret = -EINVAL;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 7122efdc6d99..e488cf910914 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,
352 u_char *buf) 352 u_char *buf)
353{ 353{
354 *retlen = 0; 354 *retlen = 0;
355 if (!mtd->read_fact_prot_reg)
356 return -EOPNOTSUPP;
355 return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf); 357 return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf);
356} 358}
357 359
@@ -369,6 +371,8 @@ static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
369 u_char *buf) 371 u_char *buf)
370{ 372{
371 *retlen = 0; 373 *retlen = 0;
374 if (!mtd->read_user_prot_reg)
375 return -EOPNOTSUPP;
372 return mtd->read_user_prot_reg(mtd, from, len, retlen, buf); 376 return mtd->read_user_prot_reg(mtd, from, len, retlen, buf);
373} 377}
374 378