From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: linux-kernel@vger.kernel.org,
"Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Simon Arlott" <simon@fire.lp0.eu>,
"Jason Gunthorpe" <jgunthorpe@obsidianresearch.com>,
"Jonas Gorski" <jogo@openwrt.org>,
"Brian Norris" <computersforpeace@gmail.com>,
devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org,
"Rob Herring" <robh+dt@kernel.org>,
"Rafał Miłecki" <zajec5@gmail.com>,
"Hauke Mehrtens" <hauke@hauke-m.de>,
"Arnd Bergmann" <arnd@arndb.de>
Subject: [RFC PATCH 5/7] mtd: partitions: factor out "match by name" handling
Date: Fri, 4 Dec 2015 21:19:21 -0800 [thread overview]
Message-ID: <1449292763-129421-6-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1449292763-129421-1-git-send-email-computersforpeace@gmail.com>
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 <computersforpeace@gmail.com>
---
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
--
2.6.0.rc2.230.g3dd15c0
next prev parent reply other threads:[~2015-12-05 5:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-05 5:19 [RFC PATCH 0/7] mtd: partitions: add of_match_table support Brian Norris
2015-12-05 5:19 ` [RFC PATCH 1/7] mtd: move partition parsers to drivers/mtd/partitions/ Brian Norris
2015-12-05 5:19 ` [RFC PATCH 2/7] mtd: move partition parsers' Kconfig under a sub-menu Brian Norris
2015-12-05 5:19 ` [RFC PATCH 3/7] doc: dt: mtd: partition: add on-flash format binding Brian Norris
2015-12-05 11:39 ` Jonas Gorski
2015-12-05 21:33 ` Michal Suchanek
2015-12-07 1:36 ` David Gibson
2015-12-10 20:43 ` Brian Norris
2015-12-11 15:58 ` Michal Suchanek
2015-12-12 5:51 ` David Gibson
2015-12-14 10:22 ` Geert Uytterhoeven
2015-12-14 12:28 ` Michal Suchanek
2015-12-15 6:00 ` David Gibson
2015-12-15 10:03 ` Geert Uytterhoeven
2015-12-17 1:05 ` David Gibson
2015-12-07 3:07 ` Rob Herring
2015-12-05 5:19 ` [RFC PATCH 4/7] mtd: add of_match_mtd_parser() and of_mtd_match_mtd_parser() helpers Brian Norris
2015-12-07 2:45 ` Rob Herring
2015-12-07 18:13 ` Brian Norris
2015-12-07 19:00 ` Rob Herring
2015-12-05 5:19 ` Brian Norris [this message]
2015-12-05 5:19 ` [RFC PATCH 6/7] RFC: mtd: partitions: enable of_match_table matching Brian Norris
2015-12-05 5:19 ` [RFC PATCH 7/7] mtd: partitions: add Google's FMAP partition parser Brian Norris
2015-12-05 10:15 ` [RFC PATCH 0/7] mtd: partitions: add of_match_table support Geert Uytterhoeven
2015-12-05 18:06 ` Michal Suchanek
2015-12-10 20:54 ` Brian Norris
2015-12-11 8:44 ` Geert Uytterhoeven
2015-12-11 15:34 ` Michal Suchanek
2015-12-11 16:00 ` Geert Uytterhoeven
2015-12-11 16:18 ` Michal Suchanek
2015-12-12 1:33 ` Brian Norris
2015-12-14 10:15 ` Geert Uytterhoeven
2015-12-05 11:35 ` Jonas Gorski
2015-12-10 21:06 ` Brian Norris
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=1449292763-129421-6-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=arnd@arndb.de \
--cc=boris.brezillon@free-electrons.com \
--cc=devicetree-spec@vger.kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=hauke@hauke-m.de \
--cc=jgunthorpe@obsidianresearch.com \
--cc=jogo@openwrt.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=robh+dt@kernel.org \
--cc=simon@fire.lp0.eu \
--cc=zajec5@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;
as well as URLs for NNTP newsgroup(s).