summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/peb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/peb.c')
-rw-r--r--drivers/mtd/peb.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index c35b63f2fd..388db7f587 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -130,6 +130,33 @@ int mtd_num_pebs(struct mtd_info *mtd)
}
/**
+ * mtd_skip_bad - skip bad blocks
+ * @mtd: mtd device
+ * @pnum: The number of the block
+ *
+ * This function skips bad blocks beginning from @pnum. Returns 0 for success and
+ * a negative error code otherwise. on successful exit @pnum points to the next
+ * good block.
+ */
+int mtd_skip_bad(struct mtd_info *mtd, int *pnum)
+{
+ if (*pnum < 0)
+ return -EINVAL;
+
+ while (1) {
+ loff_t offset = (uint64_t)mtd->erasesize * *pnum;
+
+ if (offset >= mtd->size)
+ return -ENOSPC;
+
+ if (!mtd_block_isbad(mtd, offset))
+ return 0;
+
+ *pnum = *pnum + 1;
+ }
+}
+
+/**
* mtd_peb_mark_bad - mark a physical eraseblock as bad
* @mtd: mtd device
* @pnum: The number of the block