developer | ec4ebe4 | 2022-04-12 11:17:45 +0800 | [diff] [blame] | 1 | From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> |
| 2 | Date: Thu, 6 May 2021 12:33:58 +0200 |
| 3 | Subject: [PATCH] mtd: parsers: ofpart: fix parsing subpartitions |
| 4 | MIME-Version: 1.0 |
| 5 | Content-Type: text/plain; charset=UTF-8 |
| 6 | Content-Transfer-Encoding: 8bit |
| 7 | |
| 8 | ofpart was recently patched to not scan random partition nodes as |
| 9 | subpartitions. That change unfortunately broke scanning valid |
| 10 | subpartitions like: |
| 11 | |
| 12 | partitions { |
| 13 | compatible = "fixed-partitions"; |
| 14 | #address-cells = <1>; |
| 15 | #size-cells = <1>; |
| 16 | |
| 17 | partition@0 { |
| 18 | compatible = "fixed-partitions"; |
| 19 | label = "bootloader"; |
| 20 | reg = <0x0 0x100000>; |
| 21 | |
| 22 | partition@0 { |
| 23 | label = "config"; |
| 24 | reg = <0x80000 0x80000>; |
| 25 | }; |
| 26 | }; |
| 27 | }; |
| 28 | |
| 29 | Fix that regression by adding 1 more code path. We actually need 3 |
| 30 | conditional blocks to support 3 possible cases. This change also makes |
| 31 | code easier to understand & follow. |
| 32 | |
| 33 | Reported-by: David Bauer <mail@david-bauer.net> |
| 34 | Fixes: 2d751203aacf ("mtd: parsers: ofpart: limit parsing of deprecated DT syntax |
| 35 | Signed-off-by: Rafał Miłecki <rafal@milecki.pl> |
| 36 | --- |
| 37 | drivers/mtd/parsers/ofpart_core.c | 26 ++++++++++++++------------ |
| 38 | 1 file changed, 14 insertions(+), 12 deletions(-) |
| 39 | |
| 40 | --- a/drivers/mtd/parsers/ofpart_core.c |
| 41 | +++ b/drivers/mtd/parsers/ofpart_core.c |
| 42 | @@ -57,20 +57,22 @@ static int parse_fixed_partitions(struct |
| 43 | if (!mtd_node) |
| 44 | return 0; |
| 45 | |
| 46 | - ofpart_node = of_get_child_by_name(mtd_node, "partitions"); |
| 47 | - if (!ofpart_node && !mtd_is_partition(master)) { |
| 48 | - /* |
| 49 | - * We might get here even when ofpart isn't used at all (e.g., |
| 50 | - * when using another parser), so don't be louder than |
| 51 | - * KERN_DEBUG |
| 52 | - */ |
| 53 | - pr_debug("%s: 'partitions' subnode not found on %pOF. Trying to parse direct subnodes as partitions.\n", |
| 54 | - master->name, mtd_node); |
| 55 | + if (!mtd_is_partition(master)) { /* Master */ |
| 56 | + ofpart_node = of_get_child_by_name(mtd_node, "partitions"); |
| 57 | + if (!ofpart_node) { |
| 58 | + /* |
| 59 | + * We might get here even when ofpart isn't used at all (e.g., |
| 60 | + * when using another parser), so don't be louder than |
| 61 | + * KERN_DEBUG |
| 62 | + */ |
| 63 | + pr_debug("%s: 'partitions' subnode not found on %pOF. Trying to parse direct subnodes as partitions.\n", |
| 64 | + master->name, mtd_node); |
| 65 | + ofpart_node = mtd_node; |
| 66 | + dedicated = false; |
| 67 | + } |
| 68 | + } else { /* Partition */ |
| 69 | ofpart_node = mtd_node; |
| 70 | - dedicated = false; |
| 71 | } |
| 72 | - if (!ofpart_node) |
| 73 | - return 0; |
| 74 | |
| 75 | of_id = of_match_node(parse_ofpart_match_table, ofpart_node); |
| 76 | if (dedicated && !of_id) { |