summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
commit2a17e75a976d11c1712972d29813094b8020ac35 (patch)
treeea0e991c927752937803d72a5411f7159365aa83 /drivers/mtd
parenta5f75fe8175aefec5b7cefaadc5359096c8eb22c (diff)
parent7185b353c96e1e831533eeaaada06ad9bebf84a2 (diff)
downloadbarebox-2a17e75a976d11c1712972d29813094b8020ac35.tar.gz
barebox-2a17e75a976d11c1712972d29813094b8020ac35.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/peb.c27
-rw-r--r--drivers/mtd/ubi/fastmap.c3
2 files changed, 29 insertions, 1 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
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 84c2912bf5..32b60ccad8 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1051,7 +1051,8 @@ int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count)
void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol)
{
- kfree(vol->checkmap);
+ if (vol)
+ kfree(vol->checkmap);
}
/**