aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/mtd/mtdcore.c73
-rw-r--r--include/linux/mtd/mtd.h70
2 files changed, 84 insertions, 59 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{
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index fa20a8f0463a..726c2d1b2589 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -273,65 +273,17 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
273 return mtd->_write_oob(mtd, to, ops); 273 return mtd->_write_oob(mtd, to, ops);
274} 274}
275 275
276/* 276int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf,
277 * Method to access the protection register area, present in some flash 277 size_t len);
278 * devices. The user data is one time programmable but the factory data is read 278int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
279 * only. 279 size_t *retlen, u_char *buf);
280 */ 280int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf,
281static inline int mtd_get_fact_prot_info(struct mtd_info *mtd, 281 size_t len);
282 struct otp_info *buf, size_t len) 282int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
283{ 283 size_t *retlen, u_char *buf);
284 if (!mtd->_get_fact_prot_info) 284int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
285 return -EOPNOTSUPP; 285 size_t *retlen, u_char *buf);
286 return mtd->_get_fact_prot_info(mtd, buf, len); 286int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
287}
288
289static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
290 size_t len, size_t *retlen,
291 u_char *buf)
292{
293 *retlen = 0;
294 if (!mtd->_read_fact_prot_reg)
295 return -EOPNOTSUPP;
296 return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf);
297}
298
299static inline int mtd_get_user_prot_info(struct mtd_info *mtd,
300 struct otp_info *buf,
301 size_t len)
302{
303 if (!mtd->_get_user_prot_info)
304 return -EOPNOTSUPP;
305 return mtd->_get_user_prot_info(mtd, buf, len);
306}
307
308static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
309 size_t len, size_t *retlen,
310 u_char *buf)
311{
312 *retlen = 0;
313 if (!mtd->_read_user_prot_reg)
314 return -EOPNOTSUPP;
315 return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf);
316}
317
318static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to,
319 size_t len, size_t *retlen,
320 u_char *buf)
321{
322 *retlen = 0;
323 if (!mtd->_write_user_prot_reg)
324 return -EOPNOTSUPP;
325 return mtd->_write_user_prot_reg(mtd, to, len, retlen, buf);
326}
327
328static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
329 size_t len)
330{
331 if (!mtd->_lock_user_prot_reg)
332 return -EOPNOTSUPP;
333 return mtd->_lock_user_prot_reg(mtd, from, len);
334}
335 287
336int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, 288int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
337 unsigned long count, loff_t to, size_t *retlen); 289 unsigned long count, loff_t to, size_t *retlen);