Skip to content

Commit 3813456

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: do not use mtd->lock, unlock and is_locked directly
Instead, call the corresponding MTD API function which will return '-EOPNOTSUPP' if the operation is not supported. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 327cf29 commit 3813456

5 files changed

Lines changed: 19 additions & 29 deletions

File tree

‎drivers/mtd/maps/scb2_flash.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ scb2_flash_remove(struct pci_dev *dev)
204204
return;
205205

206206
/* disable flash writes */
207-
if (scb2_mtd->lock)
208-
mtd_lock(scb2_mtd, 0, scb2_mtd->size);
207+
mtd_lock(scb2_mtd, 0, scb2_mtd->size);
209208

210209
mtd_device_unregister(scb2_mtd);
211210
map_destroy(scb2_mtd);

‎drivers/mtd/mtdchar.c‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
814814
if (copy_from_user(&einfo, argp, sizeof(einfo)))
815815
return -EFAULT;
816816

817-
if (!mtd->lock)
818-
ret = -EOPNOTSUPP;
819-
else
820-
ret = mtd_lock(mtd, einfo.start, einfo.length);
817+
ret = mtd_lock(mtd, einfo.start, einfo.length);
821818
break;
822819
}
823820

@@ -828,10 +825,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
828825
if (copy_from_user(&einfo, argp, sizeof(einfo)))
829826
return -EFAULT;
830827

831-
if (!mtd->unlock)
832-
ret = -EOPNOTSUPP;
833-
else
834-
ret = mtd_unlock(mtd, einfo.start, einfo.length);
828+
ret = mtd_unlock(mtd, einfo.start, einfo.length);
835829
break;
836830
}
837831

@@ -842,10 +836,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
842836
if (copy_from_user(&einfo, argp, sizeof(einfo)))
843837
return -EFAULT;
844838

845-
if (!mtd->is_locked)
846-
ret = -EOPNOTSUPP;
847-
else
848-
ret = mtd_is_locked(mtd, einfo.start, einfo.length);
839+
ret = mtd_is_locked(mtd, einfo.start, einfo.length);
849840
break;
850841
}
851842

‎drivers/mtd/mtdconcat.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,9 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
555555
else
556556
size = len;
557557

558-
if (subdev->lock) {
559-
err = mtd_lock(subdev, ofs, size);
560-
if (err)
561-
break;
562-
} else
563-
err = -EOPNOTSUPP;
558+
err = mtd_lock(subdev, ofs, size);
559+
if (err)
560+
break;
564561

565562
len -= size;
566563
if (len == 0)
@@ -595,12 +592,9 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
595592
else
596593
size = len;
597594

598-
if (subdev->unlock) {
599-
err = mtd_unlock(subdev, ofs, size);
600-
if (err)
601-
break;
602-
} else
603-
err = -EOPNOTSUPP;
595+
err = mtd_unlock(subdev, ofs, size);
596+
if (err)
597+
break;
604598

605599
len -= size;
606600
if (len == 0)

‎drivers/mtd/mtdcore.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ int add_mtd_device(struct mtd_info *mtd)
339339
mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
340340

341341
/* Some chips always power up locked. Unlock them now */
342-
if ((mtd->flags & MTD_WRITEABLE)
343-
&& (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) {
344-
if (mtd_unlock(mtd, 0, mtd->size))
342+
if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) {
343+
error = mtd_unlock(mtd, 0, mtd->size);
344+
if (error && error != -EOPNOTSUPP)
345345
printk(KERN_WARNING
346346
"%s: unlock failed, writes may not work\n",
347347
mtd->name);

‎include/linux/mtd/mtd.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,22 @@ static inline void mtd_sync(struct mtd_info *mtd)
406406
/* Chip-supported device locking */
407407
static inline int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
408408
{
409+
if (!mtd->lock)
410+
return -EOPNOTSUPP;
409411
return mtd->lock(mtd, ofs, len);
410412
}
411413

412414
static inline int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
413415
{
416+
if (!mtd->unlock)
417+
return -EOPNOTSUPP;
414418
return mtd->unlock(mtd, ofs, len);
415419
}
416420

417421
static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
418422
{
423+
if (!mtd->is_locked)
424+
return -EOPNOTSUPP;
419425
return mtd->is_locked(mtd, ofs, len);
420426
}
421427

0 commit comments

Comments
 (0)