Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Artem Bityutskiy and committed by
David Woodhouse
38134565 327cf292

+19 -29
+1 -2
drivers/mtd/maps/scb2_flash.c
··· 204 204 return; 205 205 206 206 /* 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); 209 208 210 209 mtd_device_unregister(scb2_mtd); 211 210 map_destroy(scb2_mtd);
+3 -12
drivers/mtd/mtdchar.c
··· 814 814 if (copy_from_user(&einfo, argp, sizeof(einfo))) 815 815 return -EFAULT; 816 816 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); 821 818 break; 822 819 } 823 820 ··· 825 828 if (copy_from_user(&einfo, argp, sizeof(einfo))) 826 829 return -EFAULT; 827 830 828 - if (!mtd->unlock) 829 - ret = -EOPNOTSUPP; 830 - else 831 - ret = mtd_unlock(mtd, einfo.start, einfo.length); 831 + ret = mtd_unlock(mtd, einfo.start, einfo.length); 832 832 break; 833 833 } 834 834 ··· 836 842 if (copy_from_user(&einfo, argp, sizeof(einfo))) 837 843 return -EFAULT; 838 844 839 - if (!mtd->is_locked) 840 - ret = -EOPNOTSUPP; 841 - else 842 - ret = mtd_is_locked(mtd, einfo.start, einfo.length); 845 + ret = mtd_is_locked(mtd, einfo.start, einfo.length); 843 846 break; 844 847 } 845 848
+6 -12
drivers/mtd/mtdconcat.c
··· 555 555 else 556 556 size = len; 557 557 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; 564 561 565 562 len -= size; 566 563 if (len == 0) ··· 592 595 else 593 596 size = len; 594 597 595 - if (subdev->unlock) { 596 - err = mtd_unlock(subdev, ofs, size); 597 - if (err) 598 - break; 599 - } else 600 - err = -EOPNOTSUPP; 598 + err = mtd_unlock(subdev, ofs, size); 599 + if (err) 600 + break; 601 601 602 602 len -= size; 603 603 if (len == 0)
+3 -3
drivers/mtd/mtdcore.c
··· 339 339 mtd->writesize_mask = (1 << mtd->writesize_shift) - 1; 340 340 341 341 /* 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) 345 345 printk(KERN_WARNING 346 346 "%s: unlock failed, writes may not work\n", 347 347 mtd->name);
+6
include/linux/mtd/mtd.h
··· 406 406 /* Chip-supported device locking */ 407 407 static inline int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 408 408 { 409 + if (!mtd->lock) 410 + return -EOPNOTSUPP; 409 411 return mtd->lock(mtd, ofs, len); 410 412 } 411 413 412 414 static inline int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 413 415 { 416 + if (!mtd->unlock) 417 + return -EOPNOTSUPP; 414 418 return mtd->unlock(mtd, ofs, len); 415 419 } 416 420 417 421 static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) 418 422 { 423 + if (!mtd->is_locked) 424 + return -EOPNOTSUPP; 419 425 return mtd->is_locked(mtd, ofs, len); 420 426 } 421 427