1 From 0dbe4ea78d69756efeb0bba0764f6bd4a9ee9567 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 16 Jan 2018 16:45:42 +0100
4 Subject: [PATCH] mtd: get rid of the mtd_add_device_partitions()
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This simplifies code a bit by:
10 1) Avoiding an extra (tiny) function
11 2) Checking for amount of parsed (found) partitions just once
12 3) Avoiding clearing/filling struct mtd_partitions manually
14 With this commit proper functions are called directly from the
15 mtd_device_parse_register(). It doesn't need to use minor tricks like
16 memsetting struct to 0 to trigger an expected
17 mtd_add_device_partitions() behavior.
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
20 Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
22 drivers/mtd/mtdcore.c | 43 ++++++++++++-------------------------------
23 1 file changed, 12 insertions(+), 31 deletions(-)
25 --- a/drivers/mtd/mtdcore.c
26 +++ b/drivers/mtd/mtdcore.c
27 @@ -636,21 +636,6 @@ out_error:
31 -static int mtd_add_device_partitions(struct mtd_info *mtd,
32 - struct mtd_partitions *parts)
34 - const struct mtd_partition *real_parts = parts->parts;
35 - int nbparts = parts->nr_parts;
37 - if (!nbparts && !device_is_registered(&mtd->dev))
38 - return add_mtd_device(mtd);
41 - return add_mtd_partitions(mtd, real_parts, nbparts);
47 * Set a few defaults based on the parent devices, if not provided by the
49 @@ -701,7 +686,7 @@ int mtd_device_parse_register(struct mtd
50 const struct mtd_partition *parts,
53 - struct mtd_partitions parsed;
54 + struct mtd_partitions parsed = { };
57 mtd_set_dev_defaults(mtd);
58 @@ -712,24 +697,20 @@ int mtd_device_parse_register(struct mtd
62 - memset(&parsed, 0, sizeof(parsed));
64 + /* Prefer parsed partitions over driver-provided fallback */
65 ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
66 - if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) {
67 - /* Fall back to driver-provided partitions */
68 - parsed = (struct mtd_partitions){
70 - .nr_parts = nr_parts,
72 - } else if (ret < 0) {
73 - /* Didn't come up with parsed OR fallback partitions */
74 - pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
76 - /* Don't abort on errors; we can still use unpartitioned MTD */
77 - memset(&parsed, 0, sizeof(parsed));
78 + if (!ret && parsed.nr_parts) {
79 + parts = parsed.parts;
80 + nr_parts = parsed.nr_parts;
83 - ret = mtd_add_device_partitions(mtd, &parsed);
85 + ret = add_mtd_partitions(mtd, parts, nr_parts);
86 + else if (!device_is_registered(&mtd->dev))
87 + ret = add_mtd_device(mtd);