Skip to content

Commit 95e6b1f

Browse files
committed
of: use kbasename instead of open coding
Several places in DT code open code the equivalent of kbasename. Replace them. The behavior for root nodes in node_name_cmp will be slightly different. Instead of comparing "/", "" will be compared. The comparison will be the same. Reviewed-by: Andy Shevchenko <andy.shevhchenko@gmail.com> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 8ee8a0e commit 95e6b1f

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

‎drivers/of/base.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,7 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent,
773773
return NULL;
774774

775775
__for_each_child_of_node(parent, child) {
776-
const char *name = strrchr(child->full_name, '/');
777-
if (WARN(!name, "malformed device_node %s\n", child->full_name))
778-
continue;
779-
name++;
776+
const char *name = kbasename(child->full_name);
780777
if (strncmp(path, name, len) == 0 && (strlen(name) == len))
781778
return child;
782779
}

‎drivers/of/platform.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void of_device_make_bus_id(struct device *dev)
9999

100100
/* format arguments only used if dev_name() resolves to NULL */
101101
dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s",
102-
strrchr(node->full_name, '/') + 1, dev_name(dev));
102+
kbasename(node->full_name), dev_name(dev));
103103
node = node->parent;
104104
}
105105
}

‎drivers/of/resolver.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay,
165165
static int node_name_cmp(const struct device_node *dn1,
166166
const struct device_node *dn2)
167167
{
168-
const char *n1 = strrchr(dn1->full_name, '/') ? : "/";
169-
const char *n2 = strrchr(dn2->full_name, '/') ? : "/";
168+
const char *n1 = kbasename(dn1->full_name);
169+
const char *n2 = kbasename(dn2->full_name);
170170

171171
return of_node_cmp(n1, n2);
172172
}

0 commit comments

Comments
 (0)