aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-02-08 09:37:14 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-03-26 19:32:29 -0400
commitde3cac9357b5aa9f9f02520e5f2567b06f3f75a7 (patch)
tree4775c9b137c10bdd9b9ed51651e8ff281987f727 /drivers/mtd/mtdcore.c
parentbcb1d238716d138c9e16347fc32b3c1ae006339e (diff)
mtd: check for zero length in OTP functions
This patch changes all the OTP functions like 'mtd_get_fact_prot_info()' and makes them return zero immediately if the input 'len' parameter is 0. This is not really needed currently, but most of the other functions do this, and it is just consistent to do the same in the OTP functions. This patch also moves the OTP functions from the header file to mtdcore.c because they become a bit too big for being inlined. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 6acc4fb254e2..b274fdf5f358 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -802,6 +802,79 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
802} 802}
803EXPORT_SYMBOL_GPL(mtd_panic_write); 803EXPORT_SYMBOL_GPL(mtd_panic_write);
804 804
805/*
806 * Method to access the protection register area, present in some flash
807 * devices. The user data is one time programmable but the factory data is read
808 * only.
809 */
810int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf,
811 size_t len)
812{
813 if (!mtd->_get_fact_prot_info)
814 return -EOPNOTSUPP;
815 if (!len)
816 return 0;
817 return mtd->_get_fact_prot_info(mtd, buf, len);
818}
819EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info);
820
821int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
822 size_t *retlen, u_char *buf)
823{
824 *retlen = 0;
825 if (!mtd->_read_fact_prot_reg)
826 return -EOPNOTSUPP;
827 if (!len)
828 return 0;
829 return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf);
830}
831EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg);
832
833int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf,
834 size_t len)
835{
836 if (!mtd->_get_user_prot_info)
837 return -EOPNOTSUPP;
838 if (!len)
839 return 0;
840 return mtd->_get_user_prot_info(mtd, buf, len);
841}
842EXPORT_SYMBOL_GPL(mtd_get_user_prot_info);
843
844int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
845 size_t *retlen, u_char *buf)
846{
847 *retlen = 0;
848 if (!mtd->_read_user_prot_reg)
849 return -EOPNOTSUPP;
850 if (!len)
851 return 0;
852 return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf);
853}
854EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
855
856int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
857 size_t *retlen, u_char *buf)
858{
859 *retlen = 0;
860 if (!mtd->_write_user_prot_reg)
861 return -EOPNOTSUPP;
862 if (!len)
863 return 0;
864 return mtd->_write_user_prot_reg(mtd, to, len, retlen, buf);
865}
866EXPORT_SYMBOL_GPL(mtd_write_user_prot_reg);
867
868int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len)
869{
870 if (!mtd->_lock_user_prot_reg)
871 return -EOPNOTSUPP;
872 if (!len)
873 return 0;
874 return mtd->_lock_user_prot_reg(mtd, from, len);
875}
876EXPORT_SYMBOL_GPL(mtd_lock_user_prot_reg);
877
805/* Chip-supported device locking */ 878/* Chip-supported device locking */
806int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 879int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
807{ 880{