Merge tag 'devicetree-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / of / pdt.c
index 4fc0fd96ed0497a8f1664b6dc95a840fbc025905..d3185063d369c5c0c42f85162aaaae2cb74e0654 100644 (file)
@@ -30,24 +30,7 @@ unsigned int of_pdt_unique_id __initdata;
 
 static char * __init of_pdt_build_full_name(struct device_node *dp)
 {
-       int len, ourlen, plen;
-       char *n;
-
-       dp->path_component_name = build_path_component(dp);
-
-       plen = strlen(dp->parent->full_name);
-       ourlen = strlen(dp->path_component_name);
-       len = ourlen + plen + 2;
-
-       n = prom_early_alloc(len);
-       strcpy(n, dp->parent->full_name);
-       if (!of_node_is_root(dp->parent)) {
-               strcpy(n + plen, "/");
-               plen++;
-       }
-       strcpy(n + plen, dp->path_component_name);
-
-       return n;
+       return build_path_component(dp);
 }
 
 #else /* CONFIG_SPARC */
@@ -58,23 +41,21 @@ static inline void irq_trans_init(struct device_node *dp) { }
 static char * __init of_pdt_build_full_name(struct device_node *dp)
 {
        static int failsafe_id = 0; /* for generating unique names on failure */
+       const char *name;
+       char path[256];
        char *buf;
        int len;
 
-       if (of_pdt_prom_ops->pkg2path(dp->phandle, NULL, 0, &len))
-               goto failsafe;
-
-       buf = prom_early_alloc(len + 1);
-       if (of_pdt_prom_ops->pkg2path(dp->phandle, buf, len, &len))
-               goto failsafe;
-       return buf;
+       if (!of_pdt_prom_ops->pkg2path(dp->phandle, path, sizeof(path), &len)) {
+               name = kbasename(path);
+               buf = prom_early_alloc(strlen(name) + 1);
+               strcpy(buf, name);
+               return buf;
+       }
 
- failsafe:
-       buf = prom_early_alloc(strlen(dp->parent->full_name) +
-                              strlen(dp->name) + 16);
-       sprintf(buf, "%s/%s@unknown%i",
-               of_node_is_root(dp->parent) ? "" : dp->parent->full_name,
-               dp->name, failsafe_id++);
+       name = of_get_property(dp, "name", &len);
+       buf = prom_early_alloc(len + 16);
+       sprintf(buf, "%s@unknown%i", name, failsafe_id++);
        pr_err("%s: pkg2path failed; assigning %s\n", __func__, buf);
        return buf;
 }
@@ -179,6 +160,8 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
        dp->properties = of_pdt_build_prop_list(node);
 
+       dp->full_name = of_pdt_build_full_name(dp);
+
        irq_trans_init(dp);
 
        return dp;
@@ -202,8 +185,6 @@ static struct device_node * __init of_pdt_build_tree(struct device_node *parent,
                        ret = dp;
                prev_sibling = dp;
 
-               dp->full_name = of_pdt_build_full_name(dp);
-
                dp->child = of_pdt_build_tree(dp, of_pdt_prom_ops->getchild(node));
 
                node = of_pdt_prom_ops->getsibling(node);
@@ -223,9 +204,6 @@ void __init of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops)
        of_pdt_prom_ops = ops;
 
        of_root = of_pdt_create_node(root_node, NULL);
-#if defined(CONFIG_SPARC)
-       of_root->path_component_name = "";
-#endif
        of_root->full_name = "/";
 
        of_root->child = of_pdt_build_tree(of_root,