mtd: unify initialization of erase_info->fail_addr
[deliverable/linux.git] / drivers / mtd / mtdcore.c
index b9b28647adefee05755fb8a99cabc47e2a1d7a6f..c837507dfb1c73021da2a47eebd975bd40573ef9 100644 (file)
@@ -695,6 +695,12 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
                return -EINVAL;
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
+       instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
+       if (!instr->len) {
+               instr->state = MTD_ERASE_DONE;
+               mtd_erase_callback(instr);
+               return 0;
+       }
        return mtd->_erase(mtd, instr);
 }
 EXPORT_SYMBOL_GPL(mtd_erase);
@@ -706,10 +712,15 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
              void **virt, resource_size_t *phys)
 {
        *retlen = 0;
+       *virt = NULL;
+       if (phys)
+               *phys = 0;
        if (!mtd->_point)
                return -EOPNOTSUPP;
        if (from < 0 || from > mtd->size || len > mtd->size - from)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_point(mtd, from, len, retlen, virt, phys);
 }
 EXPORT_SYMBOL_GPL(mtd_point);
@@ -721,6 +732,8 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
                return -EOPNOTSUPP;
        if (from < 0 || from > mtd->size || len > mtd->size - from)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_unpoint(mtd, from, len);
 }
 EXPORT_SYMBOL_GPL(mtd_unpoint);
@@ -744,8 +757,11 @@ EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
             u_char *buf)
 {
+       *retlen = 0;
        if (from < 0 || from > mtd->size || len > mtd->size - from)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_read(mtd, from, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_read);
@@ -758,6 +774,8 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
                return -EINVAL;
        if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
+       if (!len)
+               return 0;
        return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
@@ -779,10 +797,85 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
                return -EINVAL;
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
+       if (!len)
+               return 0;
        return mtd->_panic_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_panic_write);
 
+/*
+ * Method to access the protection register area, present in some flash
+ * devices. The user data is one time programmable but the factory data is read
+ * only.
+ */
+int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf,
+                          size_t len)
+{
+       if (!mtd->_get_fact_prot_info)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_get_fact_prot_info(mtd, buf, len);
+}
+EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info);
+
+int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
+                          size_t *retlen, u_char *buf)
+{
+       *retlen = 0;
+       if (!mtd->_read_fact_prot_reg)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf);
+}
+EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg);
+
+int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf,
+                          size_t len)
+{
+       if (!mtd->_get_user_prot_info)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_get_user_prot_info(mtd, buf, len);
+}
+EXPORT_SYMBOL_GPL(mtd_get_user_prot_info);
+
+int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
+                          size_t *retlen, u_char *buf)
+{
+       *retlen = 0;
+       if (!mtd->_read_user_prot_reg)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf);
+}
+EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
+
+int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
+                           size_t *retlen, u_char *buf)
+{
+       *retlen = 0;
+       if (!mtd->_write_user_prot_reg)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_write_user_prot_reg(mtd, to, len, retlen, buf);
+}
+EXPORT_SYMBOL_GPL(mtd_write_user_prot_reg);
+
+int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len)
+{
+       if (!mtd->_lock_user_prot_reg)
+               return -EOPNOTSUPP;
+       if (!len)
+               return 0;
+       return mtd->_lock_user_prot_reg(mtd, from, len);
+}
+EXPORT_SYMBOL_GPL(mtd_lock_user_prot_reg);
+
 /* Chip-supported device locking */
 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
@@ -790,6 +883,8 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
                return -EOPNOTSUPP;
        if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_lock(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_lock);
@@ -800,6 +895,8 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
                return -EOPNOTSUPP;
        if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_unlock(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_unlock);
@@ -810,6 +907,8 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
                return -EOPNOTSUPP;
        if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
                return -EINVAL;
+       if (!len)
+               return 0;
        return mtd->_is_locked(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_is_locked);
This page took 0.043295 seconds and 5 git commands to generate.