diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c index f81705e..c26a245 100644 --- a/drivers/mtd/ubi/barebox.c +++ b/drivers/mtd/ubi/barebox.c @@ -297,3 +297,23 @@ return ubi_detach_mtd_dev(ubi_num, 1); } + +/** + * ubi_num_get_by_mtd - find the ubi number to the given mtd + * @mtd: the mtd device + * + * @return: positive or zero for a UBI number, negative error code otherwise + */ +int ubi_num_get_by_mtd(struct mtd_info *mtd) +{ + int i; + struct ubi_device *ubi; + + for (i = 0; i < UBI_MAX_DEVICES; i++) { + ubi = ubi_devices[i]; + if (ubi && mtd == ubi->mtd) + return ubi->ubi_num; + } + + return -ENOENT; +} diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h index 2002548..8c02f96 100644 --- a/include/mtd/ubi-user.h +++ b/include/mtd/ubi-user.h @@ -407,5 +407,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset, int max_beb_per1024); int ubi_detach(int ubi_num); +int ubi_num_get_by_mtd(struct mtd_info *mtd); #endif /* __UBI_USER_H__ */