aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-02-06 06:27:43 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-03-26 19:32:19 -0400
commitbcb1d238716d138c9e16347fc32b3c1ae006339e (patch)
treeccb7a9aea7b77481fa3474124218521e0c32de82 /drivers/mtd/mtdcore.c
parent0dd5235f51fb0eb0b8cef3fed35be39b8a06d7bd (diff)
mtd: move zero length verification to MTD API functions
In many places in drivers we verify for the zero length, but this is very inconsistent across drivers. This is obviously the right thing to do, though. This patch moves the check to the MTD API functions instead and removes a lot of duplication. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index b20346e9fecb..6acc4fb254e2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -695,6 +695,11 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
695 return -EINVAL; 695 return -EINVAL;
696 if (!(mtd->flags & MTD_WRITEABLE)) 696 if (!(mtd->flags & MTD_WRITEABLE))
697 return -EROFS; 697 return -EROFS;
698 if (!instr->len) {
699 instr->state = MTD_ERASE_DONE;
700 mtd_erase_callback(instr);
701 return 0;
702 }
698 return mtd->_erase(mtd, instr); 703 return mtd->_erase(mtd, instr);
699} 704}
700EXPORT_SYMBOL_GPL(mtd_erase); 705EXPORT_SYMBOL_GPL(mtd_erase);
@@ -713,6 +718,8 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
713 return -EOPNOTSUPP; 718 return -EOPNOTSUPP;
714 if (from < 0 || from > mtd->size || len > mtd->size - from) 719 if (from < 0 || from > mtd->size || len > mtd->size - from)
715 return -EINVAL; 720 return -EINVAL;
721 if (!len)
722 return 0;
716 return mtd->_point(mtd, from, len, retlen, virt, phys); 723 return mtd->_point(mtd, from, len, retlen, virt, phys);
717} 724}
718EXPORT_SYMBOL_GPL(mtd_point); 725EXPORT_SYMBOL_GPL(mtd_point);
@@ -724,6 +731,8 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
724 return -EOPNOTSUPP; 731 return -EOPNOTSUPP;
725 if (from < 0 || from > mtd->size || len > mtd->size - from) 732 if (from < 0 || from > mtd->size || len > mtd->size - from)
726 return -EINVAL; 733 return -EINVAL;
734 if (!len)
735 return 0;
727 return mtd->_unpoint(mtd, from, len); 736 return mtd->_unpoint(mtd, from, len);
728} 737}
729EXPORT_SYMBOL_GPL(mtd_unpoint); 738EXPORT_SYMBOL_GPL(mtd_unpoint);
@@ -750,6 +759,8 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
750 *retlen = 0; 759 *retlen = 0;
751 if (from < 0 || from > mtd->size || len > mtd->size - from) 760 if (from < 0 || from > mtd->size || len > mtd->size - from)
752 return -EINVAL; 761 return -EINVAL;
762 if (!len)
763 return 0;
753 return mtd->_read(mtd, from, len, retlen, buf); 764 return mtd->_read(mtd, from, len, retlen, buf);
754} 765}
755EXPORT_SYMBOL_GPL(mtd_read); 766EXPORT_SYMBOL_GPL(mtd_read);
@@ -762,6 +773,8 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
762 return -EINVAL; 773 return -EINVAL;
763 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE)) 774 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
764 return -EROFS; 775 return -EROFS;
776 if (!len)
777 return 0;
765 return mtd->_write(mtd, to, len, retlen, buf); 778 return mtd->_write(mtd, to, len, retlen, buf);
766} 779}
767EXPORT_SYMBOL_GPL(mtd_write); 780EXPORT_SYMBOL_GPL(mtd_write);
@@ -783,6 +796,8 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
783 return -EINVAL; 796 return -EINVAL;
784 if (!(mtd->flags & MTD_WRITEABLE)) 797 if (!(mtd->flags & MTD_WRITEABLE))
785 return -EROFS; 798 return -EROFS;
799 if (!len)
800 return 0;
786 return mtd->_panic_write(mtd, to, len, retlen, buf); 801 return mtd->_panic_write(mtd, to, len, retlen, buf);
787} 802}
788EXPORT_SYMBOL_GPL(mtd_panic_write); 803EXPORT_SYMBOL_GPL(mtd_panic_write);
@@ -794,6 +809,8 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
794 return -EOPNOTSUPP; 809 return -EOPNOTSUPP;
795 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 810 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
796 return -EINVAL; 811 return -EINVAL;
812 if (!len)
813 return 0;
797 return mtd->_lock(mtd, ofs, len); 814 return mtd->_lock(mtd, ofs, len);
798} 815}
799EXPORT_SYMBOL_GPL(mtd_lock); 816EXPORT_SYMBOL_GPL(mtd_lock);
@@ -804,6 +821,8 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
804 return -EOPNOTSUPP; 821 return -EOPNOTSUPP;
805 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 822 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
806 return -EINVAL; 823 return -EINVAL;
824 if (!len)
825 return 0;
807 return mtd->_unlock(mtd, ofs, len); 826 return mtd->_unlock(mtd, ofs, len);
808} 827}
809EXPORT_SYMBOL_GPL(mtd_unlock); 828EXPORT_SYMBOL_GPL(mtd_unlock);
@@ -814,6 +833,8 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
814 return -EOPNOTSUPP; 833 return -EOPNOTSUPP;
815 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 834 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
816 return -EINVAL; 835 return -EINVAL;
836 if (!len)
837 return 0;
817 return mtd->_is_locked(mtd, ofs, len); 838 return mtd->_is_locked(mtd, ofs, len);
818} 839}
819EXPORT_SYMBOL_GPL(mtd_is_locked); 840EXPORT_SYMBOL_GPL(mtd_is_locked);