From patchwork Wed Aug 22 16:04:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 179345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0B9EC2C0090 for ; Thu, 23 Aug 2012 02:06:56 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T4DRH-0002JD-Fr; Wed, 22 Aug 2012 16:05:51 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T4DRC-0002Co-NH for linux-mtd@lists.infradead.org; Wed, 22 Aug 2012 16:05:49 +0000 Received: by weyr3 with SMTP id r3so743406wey.36 for ; Wed, 22 Aug 2012 09:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=qW0O/ZxJhBoWWb87egQoJ2wYdFmzDsv4a6NAmVYCZ6A=; b=AZAADMiVnBe2NFfkAK/21CJ/dvLaKPHUre4qRkefQgIY3dtT9JncLPReG1pY/S/3To +ig3o/A4r0lfjy/UyByLb9BQqdHVe4dk9JQM0r83LKFo7OHgIm+LYFsPm9G8/+u8vJ1M swcDPPaCaMWkOTr8RIwFekxqdenj17Rz2Het4XtJ1+1Zo3mDY1JVnG0xLuDS1KB23WVm AfBvISzHV/NexFu5EzkZZ6cxV12gPKv+HJKaNjySTOK2K7wlH3hn9AYCmMwWiUaTjQcK J3yDe5I2V7r43vFbefxLmu16k7B7+H79SPee4UJQUWltdmEhNP4H0ycIUxbadPmUTelG eLwQ== Received: by 10.180.82.164 with SMTP id j4mr6945103wiy.18.1345651525461; Wed, 22 Aug 2012 09:05:25 -0700 (PDT) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id l5sm13499971wix.5.2012.08.22.09.05.23 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Aug 2012 09:05:24 -0700 (PDT) From: Richard Genoud To: Artem Bityutskiy 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 Message-Id: <1345651477-5301-2-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1345651477-5301-1-git-send-email-richard.genoud@gmail.com> References: <1345651477-5301-1-git-send-email-richard.genoud@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Richard Genoud , linux-mtd@lists.infradead.org, Shmulik Ladkani X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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)