From: Richard Genoud <richard.genoud@gmail.com>
To: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Richard Genoud <richard.genoud@gmail.com>,
linux-mtd@lists.infradead.org,
Shmulik Ladkani <shmulik.ladkani@gmail.com>
Subject: [PATCH MTD-UTILS v2 1/4] libubi: factorize ubi_attach and ubi_attach_mtd code
Date: Wed, 22 Aug 2012 18:04:34 +0200 [thread overview]
Message-ID: <1345651477-5301-2-git-send-email-richard.genoud@gmail.com> (raw)
In-Reply-To: <1345651477-5301-1-git-send-email-richard.genoud@gmail.com>
The req->mtd_num value is now updated with the MTD device number found
by mtd_node_to_num.
If it's not acceptable, I'll do a static __ubi_detach_mtd() function to
prevent that, and still factorize code.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
ubi-utils/include/libubi.h | 5 +++--
ubi-utils/libubi.c | 34 ++++++++++------------------------
2 files changed, 13 insertions(+), 26 deletions(-)
diff --git a/ubi-utils/include/libubi.h b/ubi-utils/include/libubi.h
index 11a186b..bbaa78c 100644
--- a/ubi-utils/include/libubi.h
+++ b/ubi-utils/include/libubi.h
@@ -233,8 +233,9 @@ int ubi_attach_mtd(libubi_t desc, const char *node,
* device node. Otherwise functionality is similar than in function
* 'ubi_attach_mtd()' where @req->mtd_num is used.
*
- * Returns %0 in case of success and %-1 in case of failure (errno is set). The
- * newly created UBI device number is returned in @req->dev_num.
+ * Returns %0 in case of success and %-1 in case of failure (errno is set).
+ * The newly created UBI device number is returned in @req->dev_num.
+ * The MTD device number is returned in @req->mtd_num (-1 if not found)
*/
int ubi_attach(libubi_t desc, const char *node,
struct ubi_attach_request *req);
diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c
index 7736dd4..dec72c7 100644
--- a/ubi-utils/libubi.c
+++ b/ubi-utils/libubi.c
@@ -770,30 +770,16 @@ static int mtd_node_to_num(const char *mtd_dev_node)
int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req)
{
- struct ubi_attach_req r;
- int ret;
-
- if (!req->mtd_dev_node)
- /* Fallback to opening by mtd_num */
- return ubi_attach_mtd(desc, node, req);
-
- memset(&r, 0, sizeof(struct ubi_attach_req));
- r.ubi_num = req->dev_num;
- r.vid_hdr_offset = req->vid_hdr_offset;
-
- /*
- * User has passed path to device node. Lets find out MTD device number
- * of the device and pass it to the kernel.
- */
- r.mtd_num = mtd_node_to_num(req->mtd_dev_node);
- if (r.mtd_num == -1)
- return -1;
-
- ret = do_attach(node, &r);
- if (ret == 0)
- req->dev_num = r.ubi_num;
-
- return ret;
+ if (req->mtd_dev_node) {
+ /*
+ * User has passed path to device node. Lets find out MTD
+ * device number of the device and update req->mtd_num with it
+ */
+ req->mtd_num = mtd_node_to_num(req->mtd_dev_node);
+ if (req->mtd_num == -1)
+ return -1;
+ }
+ return ubi_attach_mtd(desc, node, req);
}
int ubi_detach_mtd(libubi_t desc, const char *node, int mtd_num)
--
1.7.2.5
next prev parent reply other threads:[~2012-08-22 16:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-22 16:04 [PATCH MTD-UTILS v2 0/4] introduce max_beb_per1024 in UBI_IOCATT Richard Genoud
2012-08-22 16:04 ` Richard Genoud [this message]
2012-08-23 9:27 ` [PATCH MTD-UTILS v2 1/4] libubi: factorize ubi_attach and ubi_attach_mtd code Artem Bityutskiy
2012-08-22 16:04 ` [PATCH MTD-UTILS v2 2/4] sync include/mtd/ubi-user.h: add max_beb_per1024 parameter Richard Genoud
2012-08-23 9:27 ` Artem Bityutskiy
2012-08-22 16:04 ` [PATCH MTD-UTILS v2 3/4] ubiattach: introduce max_beb_per1024 in UBI_IOCATT Richard Genoud
2012-08-23 9:29 ` Artem Bityutskiy
2012-08-27 7:23 ` Richard Genoud
2012-08-27 9:39 ` Artem Bityutskiy
2012-08-27 10:19 ` Richard Genoud
2012-08-27 10:44 ` Artem Bityutskiy
2012-08-22 16:04 ` [PATCH MTD-UTILS v2 4/4] ubiattach: fail if kernel ignores max_beb_per1024 Richard Genoud
2012-08-23 9:55 ` Artem Bityutskiy
2012-08-23 10:01 ` Richard Genoud
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=1345651477-5301-2-git-send-email-richard.genoud@gmail.com \
--to=richard.genoud@gmail.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=shmulik.ladkani@gmail.com \
/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