Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: parsers: ofpart: fix parsing subpartitions

ofpart was recently patched to not scan random partition nodes as
subpartitions. That change unfortunately broke scanning valid
subpartitions like:

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
compatible = "fixed-partitions";
label = "bootloader";
reg = <0x0 0x100000>;

partition@0 {
label = "config";
reg = <0x80000 0x80000>;
};
};
};

Fix that regression by adding 1 more code path. We actually need 3
conditional blocks to support 3 possible cases. This change also makes
code easier to understand & follow.

Reported-by: David Bauer <mail@david-bauer.net>
Fixes: 2d751203aacf ("mtd: parsers: ofpart: limit parsing of deprecated DT syntax
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Tested-by: Andrew Cameron <apcameron@softhome.net>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210508173214.28365-1-zajec5@gmail.com

authored by

Rafał Miłecki and committed by
Miquel Raynal
562b4e91 3d227a0b

+14 -12
+14 -12
drivers/mtd/parsers/ofpart_core.c
··· 57 57 if (!mtd_node) 58 58 return 0; 59 59 60 - ofpart_node = of_get_child_by_name(mtd_node, "partitions"); 61 - if (!ofpart_node && !master->parent) { 62 - /* 63 - * We might get here even when ofpart isn't used at all (e.g., 64 - * when using another parser), so don't be louder than 65 - * KERN_DEBUG 66 - */ 67 - pr_debug("%s: 'partitions' subnode not found on %pOF. Trying to parse direct subnodes as partitions.\n", 68 - master->name, mtd_node); 60 + if (!master->parent) { /* Master */ 61 + ofpart_node = of_get_child_by_name(mtd_node, "partitions"); 62 + if (!ofpart_node) { 63 + /* 64 + * We might get here even when ofpart isn't used at all (e.g., 65 + * when using another parser), so don't be louder than 66 + * KERN_DEBUG 67 + */ 68 + pr_debug("%s: 'partitions' subnode not found on %pOF. Trying to parse direct subnodes as partitions.\n", 69 + master->name, mtd_node); 70 + ofpart_node = mtd_node; 71 + dedicated = false; 72 + } 73 + } else { /* Partition */ 69 74 ofpart_node = mtd_node; 70 - dedicated = false; 71 75 } 72 - if (!ofpart_node) 73 - return 0; 74 76 75 77 of_id = of_match_node(parse_ofpart_match_table, ofpart_node); 76 78 if (dedicated && !of_id) {