]> www.infradead.org Git - mtd-utils.git/commitdiff
libubi: factorize ubi_attach and ubi_attach_mtd code
authorRichard Genoud <richard.genoud@gmail.com>
Wed, 22 Aug 2012 16:04:34 +0000 (18:04 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 23 Aug 2012 08:31:36 +0000 (11:31 +0300)
The req->mtd_num value is now updated with the MTD device number found
by mtd_node_to_num.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
ubi-utils/include/libubi.h
ubi-utils/libubi.c

index 11a186b2f7e4706a45abdef8aac2efaad3106e39..bbaa78c6fd94752eb5c1734ed539f5f4969ed6db 100644 (file)
@@ -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);
index 7736dd40e5446a71acb83109f464628099f39c85..dec72c76b7220616fbe7aeba7f24b85b3aa38fea 100644 (file)
@@ -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)