From c2084e9de331b42e2e343b96b49cc16261c1f7e0 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Sat, 6 Sep 2008 20:39:25 +0000 Subject: [PATCH] I managed to break dtc while working on PCI bridges: dtc only uses dev_fn as identifier for a PCI device. That gets us a name collision if we have the same dev_fn combination on multiple buses. Either we add a random unique ID to the struct name or we integrate the path to the parent device as well. I decided to go for integration of parent device path. With the following device tree /{ cpus {}; domain@0 { bus@0 { pci@0,0 { }; pci@1,1 { }; pci@f,0 { bus@1 { pci@0,0 { }; }; }; }; }; }; we get the old names: dev_root dev_cpus dev_domain_0 dev_bus_0 dev_pci_0_0 dev_pci_1_1 dev_pci_f_0 dev_bus_1 dev_pci_0_0 COLLISION!!! and the new names: dev_root dev_cpus dev_domain_0 dev_domain_0_bus_0 dev_domain_0_bus_0_pci_0_0 dev_domain_0_bus_0_pci_1_1 dev_domain_0_bus_0_pci_f_0 dev_domain_0_bus_0_pci_f_0_bus_1 dev_domain_0_bus_0_pci_f_0_bus_1_pci_0_0 Ron would like shorter names because they only have to be machine-readable. That's left for another patch. Signed-off-by: Carl-Daniel Hailfinger Acked-by: Ronald G. Minnich git-svn-id: svn://coreboot.org/repository/coreboot-v3@860 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- util/dtc/flattree.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/dtc/flattree.c b/util/dtc/flattree.c index 59aa19613f..6fb34b92c1 100644 --- a/util/dtc/flattree.c +++ b/util/dtc/flattree.c @@ -1311,8 +1311,22 @@ void labeltree(struct node *tree) { struct node *child; + char *tmp1; + char *tmp2; tree->label = clean(tree->name, 1); + if (tree->parent && tree->label) { + tmp1 = strdup(tree->parent->label); + if (strlen(tmp1)) { + tmp2 = tree->label; + tree->label = malloc(strlen(tmp1) + strlen(tmp2) + 2); + strcpy(tree->label, tmp1); + strcat(tree->label, "_"); + strcat(tree->label, tmp2); + free(tmp2); + } + free(tmp1); + } if (tree->next_sibling) labeltree(tree->next_sibling);