Skip to content

Commit 7554769

Browse files
Boris Brezillonrichardweinberger
authored andcommitted
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>
1 parent 9a5f09a commit 7554769

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

drivers/mtd/ubi/eba.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
311311
spin_unlock(&ubi->ltree_lock);
312312
}
313313

314+
/**
315+
* ubi_eba_is_mapped - check if a LEB is mapped.
316+
* @vol: volume description object
317+
* @lnum: logical eraseblock number
318+
*
319+
* This function returns true if the LEB is mapped, false otherwise.
320+
*/
321+
bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum)
322+
{
323+
return vol->eba_tbl[lnum] >= 0;
324+
}
325+
314326
/**
315327
* ubi_eba_unmap_leb - un-map logical eraseblock.
316328
* @ubi: UBI device description object

drivers/mtd/ubi/kapi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum)
722722
if (vol->upd_marker)
723723
return -EBADF;
724724

725-
if (vol->eba_tbl[lnum] >= 0)
725+
if (ubi_eba_is_mapped(vol, lnum))
726726
return -EBADMSG;
727727

728728
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)
757757
if (vol->upd_marker)
758758
return -EBADF;
759759

760-
return vol->eba_tbl[lnum] >= 0;
760+
return ubi_eba_is_mapped(vol, lnum);
761761
}
762762
EXPORT_SYMBOL_GPL(ubi_is_mapped);
763763

drivers/mtd/ubi/ubi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum)
849849
}
850850

851851
/* eba.c */
852+
bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum);
852853
int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
853854
int lnum);
854855
int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,

0 commit comments

Comments
 (0)