Skip to content

Commit e8b1dee

Browse files
committed
of: Use device_type helpers to access the node type
Remove directly accessing device_node.type pointer and use the accessors instead. This will eventually allow removing the type pointer. Cc: Frank Rowand <frowand.list@gmail.com> Cc: devicetree@vger.kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
1 parent e31d0fc commit e8b1dee

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎drivers/of/address.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ static int of_bus_pci_match(struct device_node *np)
110110
* "vci" is for the /chaos bridge on 1st-gen PCI powermacs
111111
* "ht" is hypertransport
112112
*/
113-
return !strcmp(np->type, "pci") || !strcmp(np->type, "pciex") ||
114-
!strcmp(np->type, "vci") || !strcmp(np->type, "ht");
113+
return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
114+
of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
115115
}
116116

117117
static void of_bus_pci_count_cells(struct device_node *np,

‎drivers/of/base.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ bool of_node_name_prefix(const struct device_node *np, const char *prefix)
7979
}
8080
EXPORT_SYMBOL(of_node_name_prefix);
8181

82+
static bool __of_node_is_type(const struct device_node *np, const char *type)
83+
{
84+
const char *match = __of_get_property(np, "device_type", NULL);
85+
86+
return np && match && type && !strcmp(match, type);
87+
}
88+
8289
int of_n_addr_cells(struct device_node *np)
8390
{
8491
u32 cells;
@@ -482,7 +489,7 @@ static int __of_device_is_compatible(const struct device_node *device,
482489

483490
/* Matching type is better than matching name */
484491
if (type && type[0]) {
485-
if (!device->type || of_node_cmp(type, device->type))
492+
if (!__of_node_is_type(device, type))
486493
return 0;
487494
score += 2;
488495
}
@@ -775,7 +782,7 @@ struct device_node *of_get_next_cpu_node(struct device_node *prev)
775782
}
776783
for (; next; next = next->sibling) {
777784
if (!(of_node_name_eq(next, "cpu") ||
778-
(next->type && !of_node_cmp(next->type, "cpu"))))
785+
__of_node_is_type(next, "cpu")))
779786
continue;
780787
if (of_node_get(next))
781788
break;
@@ -983,8 +990,7 @@ struct device_node *of_find_node_by_type(struct device_node *from,
983990

984991
raw_spin_lock_irqsave(&devtree_lock, flags);
985992
for_each_of_allnodes_from(from, np)
986-
if (np->type && (of_node_cmp(np->type, type) == 0)
987-
&& of_node_get(np))
993+
if (__of_node_is_type(np, type) && of_node_get(np))
988994
break;
989995
of_node_put(from);
990996
raw_spin_unlock_irqrestore(&devtree_lock, flags);
@@ -2108,9 +2114,9 @@ struct device_node *of_find_next_cache_node(const struct device_node *np)
21082114
/* OF on pmac has nodes instead of properties named "l2-cache"
21092115
* beneath CPU nodes.
21102116
*/
2111-
if (IS_ENABLED(CONFIG_PPC_PMAC) && !strcmp(np->type, "cpu"))
2117+
if (IS_ENABLED(CONFIG_PPC_PMAC) && of_node_is_type(np, "cpu"))
21122118
for_each_child_of_node(np, child)
2113-
if (!strcmp(child->type, "cache"))
2119+
if (of_node_is_type(child, "cache"))
21142120
return child;
21152121

21162122
return NULL;

‎drivers/of/device.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
209209
/* Name & Type */
210210
/* %p eats all alphanum characters, so %c must be used here */
211211
csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T',
212-
dev->of_node->type);
212+
of_node_get_device_type(dev->of_node));
213213
tsize = csize;
214214
len -= csize;
215215
if (str)
@@ -279,7 +279,7 @@ EXPORT_SYMBOL_GPL(of_device_modalias);
279279
*/
280280
void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
281281
{
282-
const char *compat;
282+
const char *compat, *type;
283283
struct alias_prop *app;
284284
struct property *p;
285285
int seen = 0;
@@ -289,8 +289,9 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
289289

290290
add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node);
291291
add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node);
292-
if (dev->of_node->type && strcmp("<NULL>", dev->of_node->type) != 0)
293-
add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type);
292+
type = of_node_get_device_type(dev->of_node);
293+
if (type)
294+
add_uevent_var(env, "OF_TYPE=%s", type);
294295

295296
/* Since the compatible field can contain pretty much anything
296297
* it's not really legal to split it out with commas. We split it

0 commit comments

Comments
 (0)