summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2018-08-29 14:19:47 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-31 08:23:30 +0200
commitea45f03e17a0dc6f2ca01bbc6842a36b4a27a3c2 (patch)
tree3f67f0e7d07929bbfb2980c76dbde0fc54404e74 /drivers/mtd/ubi
parent9f51b1b1d31f2cf1fc9afda504a372dfd5dfa067 (diff)
downloadbarebox-ea45f03e17a0dc6f2ca01bbc6842a36b4a27a3c2.tar.gz
barebox-ea45f03e17a0dc6f2ca01bbc6842a36b4a27a3c2.tar.xz
UBI: provide an helper to check whether a LEB is mapped or not
This is part of the process of hiding UBI EBA's internal to other part of the UBI implementation, so that we can add new information to the EBA table without having to patch different places in the UBI code. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/eba.c12
-rw-r--r--drivers/mtd/ubi/kapi.c4
-rw-r--r--drivers/mtd/ubi/ubi.h1
3 files changed, 15 insertions, 2 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index fd83682868..704f67dfb6 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -280,6 +280,18 @@ static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
}
/**
+ * ubi_eba_is_mapped - check if a LEB is mapped.
+ * @vol: volume description object
+ * @lnum: logical eraseblock number
+ *
+ * This function returns true if the LEB is mapped, false otherwise.
+ */
+bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum)
+{
+ return vol->eba_tbl[lnum] >= 0;
+}
+
+/**
* ubi_eba_unmap_leb - un-map logical eraseblock.
* @ubi: UBI device description object
* @vol: volume description object
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index a7be941908..e1cab763eb 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -597,7 +597,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum)
if (vol->upd_marker)
return -EBADF;
- if (vol->eba_tbl[lnum] >= 0)
+ if (ubi_eba_is_mapped(vol, lnum))
return -EBADMSG;
return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0);
@@ -632,7 +632,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum)
if (vol->upd_marker)
return -EBADF;
- return vol->eba_tbl[lnum] >= 0;
+ return ubi_eba_is_mapped(vol, lnum);
}
EXPORT_SYMBOL_GPL(ubi_is_mapped);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 4ef692fc72..5d39b0d55b 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -784,6 +784,7 @@ static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum)
}
/* eba.c */
+bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum);
int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
int lnum);
int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,