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

mtd: core: simplify (a bit) code find partition-matching dynamic OF node

1. Don't hardcode "partition-" string twice
2. Use simpler logic & use ->name to avoid of_property_read_string()
3. Use mtd_get_of_node() helper

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-1-zajec5@gmail.com

authored by

Rafał Miłecki and committed by
Miquel Raynal
c5f5d0cd 30a0b95b

+8 -9
+8 -9
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 - struct mtd_info *parent; 555 554 bool found = false; 556 555 557 556 /* Check if MTD already has a device node */ 558 - if (dev_of_node(&mtd->dev)) 557 + if (mtd_get_of_node(mtd)) 559 558 return; 560 559 561 560 /* Check if a partitions node exist */ 562 561 if (!mtd_is_partition(mtd)) 563 562 return; 564 - parent = mtd->parent; 565 - parent_dn = of_node_get(dev_of_node(&parent->dev)); 563 + 564 + parent_dn = of_node_get(mtd_get_of_node(mtd->parent)); 566 565 if (!parent_dn) 567 566 return; 568 567 ··· 574 575 575 576 /* Search if a partition is defined with the same name */ 576 577 for_each_child_of_node(partitions, mtd_dn) { 577 - offset = 0; 578 - 579 578 /* Skip partition with no/wrong prefix */ 580 - if (!of_node_name_prefix(mtd_dn, "partition-")) 579 + if (!of_node_name_prefix(mtd_dn, prefix)) 581 580 continue; 582 581 583 582 /* Label have priority. Check that first */ 584 - if (of_property_read_string(mtd_dn, "label", &pname)) { 585 - of_property_read_string(mtd_dn, "name", &pname); 583 + if (!of_property_read_string(mtd_dn, "label", &pname)) { 584 + offset = 0; 585 + } else { 586 + pname = mtd_dn->name; 586 587 offset = prefix_len; 587 588 } 588 589