mtd: partitions: factor out code calling parser

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Jul 13 10:59:05 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=01f9c7240a900d5676a8496496f2974dd36996b1
Commit:     01f9c7240a900d5676a8496496f2974dd36996b1
Parent:     df1d178879f53d7f790d4bc372aa0fc5d5423328
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Tue May 23 07:30:20 2017 +0200
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Tue Jun 20 12:59:23 2017 -0700

    mtd: partitions: factor out code calling parser
    
    This code is going to be reused for parsers matched using OF so let's
    factor it out to make this easier.
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
    Acked-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/mtdpart.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 2e152e53..7ececd3 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -807,6 +807,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)
@@ -847,16 +868,10 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
 			 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



More information about the linux-mtd-cvs mailing list