diff options
| author | Richard Genoud <richard.genoud@gmail.com> | 2012-08-22 18:04:34 +0200 | 
|---|---|---|
| committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-08-23 11:31:36 +0300 | 
| commit | 24c95043a1fd464388563f31b5f40831f74e04b3 (patch) | |
| tree | 24c5f9df7277a9d175c42183af7c95bcd82ab5bb /ubi-utils/libubi.c | |
| parent | dd6898d9ecb210e5187b95adb54a94ab12b9bd2b (diff) | |
libubi: factorize ubi_attach and ubi_attach_mtd code
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>
Diffstat (limited to 'ubi-utils/libubi.c')
| -rw-r--r-- | ubi-utils/libubi.c | 34 | 
1 files changed, 10 insertions, 24 deletions
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)  | 
