Skip to content

Commit 87e858a

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: do not use mtd->get_*_prot_info directly
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>
1 parent dac2639 commit 87e858a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎drivers/mtd/mtdchar.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,15 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
919919
struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
920920
if (!buf)
921921
return -ENOMEM;
922-
ret = -EOPNOTSUPP;
923922
switch (mfi->mode) {
924923
case MTD_FILE_MODE_OTP_FACTORY:
925-
if (mtd->get_fact_prot_info)
926-
ret = mtd_get_fact_prot_info(mtd, buf, 4096);
924+
ret = mtd_get_fact_prot_info(mtd, buf, 4096);
927925
break;
928926
case MTD_FILE_MODE_OTP_USER:
929-
if (mtd->get_user_prot_info)
930-
ret = mtd_get_user_prot_info(mtd, buf, 4096);
927+
ret = mtd_get_user_prot_info(mtd, buf, 4096);
931928
break;
932929
default:
930+
ret = -EINVAL;
933931
break;
934932
}
935933
if (ret >= 0) {

‎include/linux/mtd/mtd.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
342342
static inline int mtd_get_fact_prot_info(struct mtd_info *mtd,
343343
struct otp_info *buf, size_t len)
344344
{
345+
if (!mtd->get_fact_prot_info)
346+
return -EOPNOTSUPP;
345347
return mtd->get_fact_prot_info(mtd, buf, len);
346348
}
347349

@@ -357,6 +359,8 @@ static inline int mtd_get_user_prot_info(struct mtd_info *mtd,
357359
struct otp_info *buf,
358360
size_t len)
359361
{
362+
if (!mtd->get_user_prot_info)
363+
return -EOPNOTSUPP;
360364
return mtd->get_user_prot_info(mtd, buf, len);
361365
}
362366

0 commit comments

Comments
 (0)