Skip to content

Commit 5dc63fa

Browse files
Uwe Kleine-KönigDavid Woodhouse
authored andcommitted
mtd: mtdchar: handle chips that have user otp but no factory otp
Before this patch mtd_read_fact_prot_reg was used to check availability for both MTD_OTP_FACTORY and MTD_OTP_USER access. This made accessing user otp for chips that don't have a factory otp area impossible. So use the right wrapper depending on the intended area to be accessed. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 6b75152 commit 5dc63fa

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎drivers/mtd/mtdchar.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,28 +370,30 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
370370
{
371371
struct mtd_info *mtd = mfi->mtd;
372372
size_t retlen;
373-
int ret = 0;
374-
375-
/*
376-
* Make a fake call to mtd_read_fact_prot_reg() to check if OTP
377-
* operations are supported.
378-
*/
379-
if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP)
380-
return -EOPNOTSUPP;
381373

382374
switch (mode) {
383375
case MTD_OTP_FACTORY:
376+
if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) ==
377+
-EOPNOTSUPP)
378+
return -EOPNOTSUPP;
379+
384380
mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
385381
break;
386382
case MTD_OTP_USER:
383+
if (mtd_read_user_prot_reg(mtd, -1, 0, &retlen, NULL) ==
384+
-EOPNOTSUPP)
385+
return -EOPNOTSUPP;
386+
387387
mfi->mode = MTD_FILE_MODE_OTP_USER;
388388
break;
389-
default:
390-
ret = -EINVAL;
391389
case MTD_OTP_OFF:
390+
mfi->mode = MTD_FILE_MODE_NORMAL;
392391
break;
392+
default:
393+
return -EINVAL;
393394
}
394-
return ret;
395+
396+
return 0;
395397
}
396398
#else
397399
# define otp_select_filemode(f,m) -EOPNOTSUPP

0 commit comments

Comments
 (0)