From: Markus Pargmann <mpa@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number
Date: Thu, 10 Mar 2016 09:29:56 +0100 [thread overview]
Message-ID: <1457598600-10669-4-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1457598600-10669-1-git-send-email-mpa@pengutronix.de>
ubi_num_get_by_mtd() searches for attached ubi devices for the given mtd
and returns the number of the ubi device.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
drivers/mtd/ubi/build.c | 35 ++++++++++++++++++++++++++---------
include/mtd/ubi-user.h | 1 +
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 797022636dcb..f51d10cf0d21 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -482,6 +482,28 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
}
/**
+ * ubi_num_get_by_mtd finds the ubi number to the given mtd
+ * @param mtd mtd_info to the mtd device
+ * @return positive or null for a UBI number, negative errno 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) {
+ ubi_debug("mtd%d is already attached to ubi%d",
+ mtd->index, i);
+ return ubi->ubi_num;
+ }
+ }
+
+ return -ENOENT;
+}
+
+/**
* ubi_attach_mtd_dev - attach an MTD device.
* @mtd: MTD device description object
* @ubi_num: number to assign to the new UBI device
@@ -501,7 +523,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024)
{
struct ubi_device *ubi;
- int i, err, ref = 0;
+ int ubi_id, err, ref = 0;
if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
return -EINVAL;
@@ -515,14 +537,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
* Note, this function assumes that UBI devices creations and deletions
* are serialized, so it does not take the &ubi_devices_lock.
*/
- for (i = 0; i < UBI_MAX_DEVICES; i++) {
- ubi = ubi_devices[i];
- if (ubi && mtd == ubi->mtd) {
- ubi_debug("mtd%d is already attached to ubi%d",
- mtd->index, i);
- return -EEXIST;
- }
- }
+ ubi_id = ubi_num_get_by_mtd(mtd);
+ if (ubi_id >= 0)
+ return -EEXIST;
/*
* Make sure this MTD device is not emulated on top of an UBI volume
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 2000ef2fd00d..ab1a6630f5ee 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -407,5 +407,6 @@ struct ubi_set_vol_prop_req {
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024);
int ubi_detach_mtd_dev(int ubi_num, int anyway);
+int ubi_num_get_by_mtd(struct mtd_info *mtd);
#endif /* __UBI_USER_H__ */
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-03-10 8:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev() Markus Pargmann
2016-03-10 8:29 ` Markus Pargmann [this message]
2016-03-10 8:29 ` [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info Markus Pargmann
2016-03-10 8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
2016-03-14 7:32 ` Sascha Hauer
2016-03-10 8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
2016-03-14 7:41 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457598600-10669-4-git-send-email-mpa@pengutronix.de \
--to=mpa@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox