UBI: provide an helper to check whether a LEB is mapped or not
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Fri, 16 Sep 2016 14:59:23 +0000 (16:59 +0200)
committerRichard Weinberger <richard@nod.at>
Sun, 2 Oct 2016 20:48:14 +0000 (22:48 +0200)
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>
drivers/mtd/ubi/eba.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/ubi.h

index 180eb006e96643adc9a802a976413b813dd38c2d..32045dd3d1db86de3556a128e5d548b727aa4ed8 100644 (file)
@@ -311,6 +311,18 @@ static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
        spin_unlock(&ubi->ltree_lock);
 }
 
+/**
+ * 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
index cec7f65beb9e69b7cd77da9bf053b5d509080c12..88b1897aeb40f77771cef9ae3e9773b812a37877 100644 (file)
@@ -722,7 +722,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);
@@ -757,7 +757,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);
 
index 23c902e204aa265016ba426404480244a2d17cd5..37469805591d7107852b11900f23986d4425ac2a 100644 (file)
@@ -849,6 +849,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,