d312e081a9d4f7884aac396d9506ef47f0a748b9
[openwrt/staging/jogo.git] /
1 From 01f9c7240a900d5676a8496496f2974dd36996b1 Mon Sep 17 00:00:00 2001
2 From: Brian Norris <computersforpeace@gmail.com>
3 Date: Tue, 23 May 2017 07:30:20 +0200
4 Subject: [PATCH] mtd: partitions: factor out code calling parser
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This code is going to be reused for parsers matched using OF so let's
10 factor it out to make this easier.
11
12 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
13 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
14 Acked-by: Brian Norris <computersforpeace@gmail.com>
15 ---
16 drivers/mtd/mtdpart.c | 33 ++++++++++++++++++++++++---------
17 1 file changed, 24 insertions(+), 9 deletions(-)
18
19 --- a/drivers/mtd/mtdpart.c
20 +++ b/drivers/mtd/mtdpart.c
21 @@ -807,6 +807,27 @@ static const char * const default_mtd_pa
22 NULL
23 };
24
25 +static int mtd_part_do_parse(struct mtd_part_parser *parser,
26 + struct mtd_info *master,
27 + struct mtd_partitions *pparts,
28 + struct mtd_part_parser_data *data)
29 +{
30 + int ret;
31 +
32 + ret = (*parser->parse_fn)(master, &pparts->parts, data);
33 + pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret);
34 + if (ret <= 0)
35 + return ret;
36 +
37 + pr_notice("%d %s partitions found on MTD device %s\n", ret,
38 + parser->name, master->name);
39 +
40 + pparts->nr_parts = ret;
41 + pparts->parser = parser;
42 +
43 + return ret;
44 +}
45 +
46 /**
47 * parse_mtd_partitions - parse MTD partitions
48 * @master: the master partition (describes whole MTD device)
49 @@ -847,16 +868,10 @@ int parse_mtd_partitions(struct mtd_info
50 parser ? parser->name : NULL);
51 if (!parser)
52 continue;
53 - ret = (*parser->parse_fn)(master, &pparts->parts, data);
54 - pr_debug("%s: parser %s: %i\n",
55 - master->name, parser->name, ret);
56 - if (ret > 0) {
57 - printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
58 - ret, parser->name, master->name);
59 - pparts->nr_parts = ret;
60 - pparts->parser = parser;
61 + ret = mtd_part_do_parse(parser, master, pparts, data);
62 + /* Found partitions! */
63 + if (ret > 0)
64 return 0;
65 - }
66 mtd_part_parser_put(parser);
67 /*
68 * Stash the first error we see; only report it if no parser