From patchwork Sat Dec 5 05:19:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 552952 X-Patchwork-Delegate: computersforpeace@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1FA861402C0 for ; Sat, 5 Dec 2015 16:22:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=S8CCwczr; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a55Gj-0006l7-FR; Sat, 05 Dec 2015 05:20:25 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a55GM-0005Wa-Re for linux-mtd@lists.infradead.org; Sat, 05 Dec 2015 05:20:05 +0000 Received: by pabfh17 with SMTP id fh17so99547633pab.0 for ; Fri, 04 Dec 2015 21:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VkYKl7t0fHOtpuLPMrYoLx+kn5WQt4bBJIwNoB2vC0Y=; b=S8CCwczrs2xNc6AwJm2M0U3etdABHFRyD69XYH27CUj8FG2dlMbR2l0wkodt3wJN+n TYC4qZQJ0G5xcZtsfGxDBTo2HMbPcaORJNCEk5Tj+nvgqQ5eeKx/NTSS+oC1lPZCDc5C BxhA9GcATaDVjdXXIjwgOGz3dCnfwh2B3Y7uWazQzXbxbqMOti1lpbFDNbh++ND0BiaZ S9Betg3yuhau6BazTxe22OK4hWLvDX4pU1Ou1KNckSunb/e7rXe83sJD+vAp4MGI1ozD W1kcL/n7D9ENtjVziHdb5PKpxhfaeHLKeZlqXkeARDVk/5QysjqBsqmdbQC/SkoLwpvl jHaw== X-Received: by 10.66.234.8 with SMTP id ua8mr27010969pac.45.1449292782236; Fri, 04 Dec 2015 21:19:42 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id p86sm20357797pfi.42.2015.12.04.21.19.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Dec 2015 21:19:41 -0800 (PST) From: Brian Norris To: Subject: [RFC PATCH 5/7] mtd: partitions: factor out "match by name" handling Date: Fri, 4 Dec 2015 21:19:21 -0800 Message-Id: <1449292763-129421-6-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1449292763-129421-1-git-send-email-computersforpeace@gmail.com> References: <1449292763-129421-1-git-send-email-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151204_212003_153293_A2625910 X-CRM114-Status: GOOD ( 14.25 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.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 [2607:f8b0:400e:c03:0:0:0:230 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Arnd Bergmann , Geert Uytterhoeven , devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org, Simon Arlott , Linus Walleij , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-kernel@vger.kernel.org, Jason Gunthorpe , Jonas Gorski , Rob Herring , Hauke Mehrtens , Brian Norris MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This code structure is going to be imitated for a match-by-device-node implementation, so let's factor out a few functions to make this easier. Signed-off-by: Brian Norris --- drivers/mtd/mtdpart.c | 67 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 10bf304027dd..b3100742ddf6 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -687,23 +687,47 @@ int add_mtd_partitions(struct mtd_info *master, static DEFINE_SPINLOCK(part_parser_lock); static LIST_HEAD(part_parsers); -static struct mtd_part_parser *mtd_part_parser_get(const char *name) +static bool mtd_part_parser_match_name(struct mtd_part_parser *p, + const char *name) +{ + return !strcmp(p->name, name); +} + +static struct mtd_part_parser *__mtd_part_parser_get_by_name(const char *name) { struct mtd_part_parser *p, *ret = NULL; spin_lock(&part_parser_lock); - list_for_each_entry(p, &part_parsers, list) - if (!strcmp(p->name, name) && try_module_get(p->owner)) { + list_for_each_entry(p, &part_parsers, list) { + if (mtd_part_parser_match_name(p, name) && + try_module_get(p->owner)) { ret = p; break; } + } spin_unlock(&part_parser_lock); return ret; } +static struct mtd_part_parser *mtd_part_parser_get_by_name(const char *name) +{ + struct mtd_part_parser *p; + + /* Get parser, if already loaded */ + p = __mtd_part_parser_get_by_name(name); + if (p) + return p; + + if (request_module("%s", name)) + return NULL; + + /* Try again */ + return __mtd_part_parser_get_by_name(name); +} + static inline void mtd_part_parser_put(const struct mtd_part_parser *p) { module_put(p->owner); @@ -752,6 +776,27 @@ static const char * const default_mtd_part_types[] = { NULL }; +static int mtd_part_do_parse(struct mtd_part_parser *parser, + struct mtd_info *master, + struct mtd_partitions *pparts, + struct mtd_part_parser_data *data) +{ + int ret; + + ret = (*parser->parse_fn)(master, &pparts->parts, data); + pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); + if (ret <= 0) + return ret; + + pr_notice("%d %s partitions found on MTD device %s\n", + ret, parser->name, master->name); + + pparts->nr_parts = ret; + pparts->parser = parser; + + return ret; +} + /** * parse_mtd_partitions - parse MTD partitions * @master: the master partition (describes whole MTD device) @@ -785,23 +830,15 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types, for ( ; *types; types++) { pr_debug("%s: parsing partitions %s\n", master->name, *types); - parser = mtd_part_parser_get(*types); - if (!parser && !request_module("%s", *types)) - parser = mtd_part_parser_get(*types); + parser = mtd_part_parser_get_by_name(*types); pr_debug("%s: got parser %s\n", master->name, parser ? parser->name : NULL); if (!parser) continue; - ret = (*parser->parse_fn)(master, &pparts->parts, data); - pr_debug("%s: parser %s: %i\n", - master->name, parser->name, ret); - if (ret > 0) { - printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", - ret, parser->name, master->name); - pparts->nr_parts = ret; - pparts->parser = parser; + ret = mtd_part_do_parse(parser, master, pparts, data); + /* Found partitions! */ + if (ret > 0) return 0; - } mtd_part_parser_put(parser); /* * Stash the first error we see; only report it if no parser