提交 c5f5d0cd 编写于 作者: R Rafał Miłecki 提交者: Miquel Raynal

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: NRafał Miłecki <rafal@milecki.pl>
Signed-off-by: NMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20221004083710.27704-1-zajec5@gmail.com
上级 30a0b95b
...@@ -551,18 +551,17 @@ static void mtd_check_of_node(struct mtd_info *mtd) ...@@ -551,18 +551,17 @@ static void mtd_check_of_node(struct mtd_info *mtd)
struct device_node *partitions, *parent_dn, *mtd_dn = NULL; struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
const char *pname, *prefix = "partition-"; const char *pname, *prefix = "partition-";
int plen, mtd_name_len, offset, prefix_len; int plen, mtd_name_len, offset, prefix_len;
struct mtd_info *parent;
bool found = false; bool found = false;
/* Check if MTD already has a device node */ /* Check if MTD already has a device node */
if (dev_of_node(&mtd->dev)) if (mtd_get_of_node(mtd))
return; return;
/* Check if a partitions node exist */ /* Check if a partitions node exist */
if (!mtd_is_partition(mtd)) if (!mtd_is_partition(mtd))
return; return;
parent = mtd->parent;
parent_dn = of_node_get(dev_of_node(&parent->dev)); parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
if (!parent_dn) if (!parent_dn)
return; return;
...@@ -575,15 +574,15 @@ static void mtd_check_of_node(struct mtd_info *mtd) ...@@ -575,15 +574,15 @@ static void mtd_check_of_node(struct mtd_info *mtd)
/* Search if a partition is defined with the same name */ /* Search if a partition is defined with the same name */
for_each_child_of_node(partitions, mtd_dn) { for_each_child_of_node(partitions, mtd_dn) {
offset = 0;
/* Skip partition with no/wrong prefix */ /* Skip partition with no/wrong prefix */
if (!of_node_name_prefix(mtd_dn, "partition-")) if (!of_node_name_prefix(mtd_dn, prefix))
continue; continue;
/* Label have priority. Check that first */ /* Label have priority. Check that first */
if (of_property_read_string(mtd_dn, "label", &pname)) { if (!of_property_read_string(mtd_dn, "label", &pname)) {
of_property_read_string(mtd_dn, "name", &pname); offset = 0;
} else {
pname = mtd_dn->name;
offset = prefix_len; offset = prefix_len;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册