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

mtd: core: try to find OF node for every MTD partition

So far this feature was limited to the top-level "nvmem-cells" node.
There are multiple parsers creating partitions and subpartitions
dynamically. Extend that code to handle them too.

This allows finding partition-* node for every MTD (sub)partition.

Random example:

partitions {
compatible = "brcm,bcm947xx-cfe-partitions";

partition-firmware {
compatible = "brcm,trx";

partition-loader {
};
};
};

Cc: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20221004083710.27704-2-zajec5@gmail.com

authored by

Rafał Miłecki and committed by
Miquel Raynal
2df11f00 c5f5d0cd

+5 -12
+5 -12
drivers/mtd/mtdcore.c
··· 551 551 struct device_node *partitions, *parent_dn, *mtd_dn = NULL; 552 552 const char *pname, *prefix = "partition-"; 553 553 int plen, mtd_name_len, offset, prefix_len; 554 - bool found = false; 555 554 556 555 /* Check if MTD already has a device node */ 557 556 if (mtd_get_of_node(mtd)) 558 557 return; 559 558 560 - /* Check if a partitions node exist */ 561 559 if (!mtd_is_partition(mtd)) 562 560 return; 563 561 ··· 563 565 if (!parent_dn) 564 566 return; 565 567 566 - partitions = of_get_child_by_name(parent_dn, "partitions"); 568 + if (mtd_is_partition(mtd->parent)) 569 + partitions = of_node_get(parent_dn); 570 + else 571 + partitions = of_get_child_by_name(parent_dn, "partitions"); 567 572 if (!partitions) 568 573 goto exit_parent; 569 574 ··· 590 589 plen = strlen(pname) - offset; 591 590 if (plen == mtd_name_len && 592 591 !strncmp(mtd->name, pname + offset, plen)) { 593 - found = true; 592 + mtd_set_of_node(mtd, mtd_dn); 594 593 break; 595 594 } 596 595 } 597 596 598 - if (!found) 599 - goto exit_partitions; 600 - 601 - /* Set of_node only for nvmem */ 602 - if (of_device_is_compatible(mtd_dn, "nvmem-cells")) 603 - mtd_set_of_node(mtd, mtd_dn); 604 - 605 - exit_partitions: 606 597 of_node_put(partitions); 607 598 exit_parent: 608 599 of_node_put(parent_dn);