aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@linaro.org>2014-05-21 02:40:31 -0400
committerGrant Likely <grant.likely@linaro.org>2014-05-22 18:58:26 -0400
commit07e461cd7e73a84f0e3757932b93cc80976fd749 (patch)
tree1f3e2ce6e3c5c2d943b525078766499542aff9b3
parenteafd370dfe487facfdef499057f4eac9aa0b4bf5 (diff)
of: Ensure unique names without sacrificing determinism
The way the driver core is implemented, every device using the same bus type is required to have a unique name because a symlink to each device is created in the appropriate /sys/bus/*/devices directory, and two identical names causes a collision. The current code handles the requirement by using an globally incremented counter that is appended to the device name. It works, but it means any change to device registration will change the assigned numbers. Instead, if we build up the name by using information from the parent nodes, then it can be guaranteed to be unique without adding a random number to the end of it. Signed-off-by: Grant Likely <grant.likely@linaro.org> Cc: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> Cc: Rob Herring <robh@kernel.org>
-rw-r--r--drivers/of/platform.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index d0009b3614af..95c133a0554b 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -68,17 +68,15 @@ EXPORT_SYMBOL(of_find_device_by_node);
68 * of_device_make_bus_id - Use the device node data to assign a unique name 68 * of_device_make_bus_id - Use the device node data to assign a unique name
69 * @dev: pointer to device structure that is linked to a device tree node 69 * @dev: pointer to device structure that is linked to a device tree node
70 * 70 *
71 * This routine will first try using either the dcr-reg or the reg property 71 * This routine will first try using the translated bus address to
72 * value to derive a unique name. As a last resort it will use the node 72 * derive a unique name. If it cannot, then it will prepend names from
73 * name followed by a unique number. 73 * parent nodes until a unique name can be derived.
74 */ 74 */
75void of_device_make_bus_id(struct device *dev) 75void of_device_make_bus_id(struct device *dev)
76{ 76{
77 static atomic_t bus_no_reg_magic;
78 struct device_node *node = dev->of_node; 77 struct device_node *node = dev->of_node;
79 const __be32 *reg; 78 const __be32 *reg;
80 u64 addr; 79 u64 addr;
81 int magic;
82 80
83#ifdef CONFIG_PPC_DCR 81#ifdef CONFIG_PPC_DCR
84 /* 82 /*
@@ -100,25 +98,25 @@ void of_device_make_bus_id(struct device *dev)
100 } 98 }
101#endif /* CONFIG_PPC_DCR */ 99#endif /* CONFIG_PPC_DCR */
102 100
103 /* 101 /* Construct the name, using parent nodes if necessary to ensure uniqueness */
104 * For MMIO, get the physical address 102 while (node->parent) {
105 */ 103 /*
106 reg = of_get_property(node, "reg", NULL); 104 * If the address can be translated, then that is as much
107 if (reg) { 105 * uniqueness as we need. Make it the first component and return
108 addr = of_translate_address(node, reg); 106 */
109 if (addr != OF_BAD_ADDR) { 107 reg = of_get_property(node, "reg", NULL);
110 dev_set_name(dev, "%llx.%s", 108 if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
111 (unsigned long long)addr, node->name); 109 dev_set_name(dev, dev_name(dev) ? "%llx.%s:%s" : "%llx.%s",
110 (unsigned long long)addr, node->name,
111 dev_name(dev));
112 return; 112 return;
113 } 113 }
114 }
115 114
116 /* 115 /* format arguments only used if dev_name() resolves to NULL */
117 * No BusID, use the node name and add a globally incremented 116 dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
118 * counter (and pray...) 117 strrchr(node->full_name, '/') + 1, dev_name(dev));
119 */ 118 node = node->parent;
120 magic = atomic_add_return(1, &bus_no_reg_magic); 119 }
121 dev_set_name(dev, "%s.%d", node->name, magic - 1);
122} 120}
123 121
124/** 122/**