lib/vsprintf: Make use of fwnode API to obtain node names and separators

Instead of implementing our own means of discovering parent nodes, node
names or counting how many parents a node has, use the newly added
functions in the fwnode API to obtain that information.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Sakari Ailus 2019-10-03 15:32:16 +03:00 committed by Rafael J. Wysocki
parent 1586c5ae2f
commit a92eb7621b

View File

@ -38,6 +38,7 @@
#include <net/addrconf.h> #include <net/addrconf.h>
#include <linux/siphash.h> #include <linux/siphash.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/property.h>
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
#include <linux/blkdev.h> #include <linux/blkdev.h>
#endif #endif
@ -1872,32 +1873,25 @@ char *flags_string(char *buf, char *end, void *flags_ptr,
return format_flags(buf, end, flags, names); return format_flags(buf, end, flags, names);
} }
static const char *device_node_name_for_depth(const struct device_node *np, int depth)
{
for ( ; np && depth; depth--)
np = np->parent;
return kbasename(np->full_name);
}
static noinline_for_stack static noinline_for_stack
char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end) char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
char *end)
{ {
int depth; int depth;
const struct device_node *parent = np->parent;
/* special case for root node */ /* Loop starting from the root node to the current node. */
if (!parent) for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
return string_nocheck(buf, end, "/", default_str_spec); struct fwnode_handle *__fwnode =
fwnode_get_nth_parent(fwnode, depth);
for (depth = 0; parent->parent; depth++) buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
parent = parent->parent;
for ( ; depth >= 0; depth--) {
buf = string_nocheck(buf, end, "/", default_str_spec);
buf = string(buf, end, device_node_name_for_depth(np, depth),
default_str_spec); default_str_spec);
buf = string(buf, end, fwnode_get_name(__fwnode),
default_str_spec);
fwnode_handle_put(__fwnode);
} }
return buf; return buf;
} }
@ -1942,10 +1936,11 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
switch (*fmt) { switch (*fmt) {
case 'f': /* full_name */ case 'f': /* full_name */
buf = device_node_gen_full_name(dn, buf, end); buf = fwnode_full_name_string(of_fwnode_handle(dn), buf,
end);
break; break;
case 'n': /* name */ case 'n': /* name */
p = kbasename(of_node_full_name(dn)); p = fwnode_get_name(of_fwnode_handle(dn));
precision = str_spec.precision; precision = str_spec.precision;
str_spec.precision = strchrnul(p, '@') - p; str_spec.precision = strchrnul(p, '@') - p;
buf = string(buf, end, p, str_spec); buf = string(buf, end, p, str_spec);
@ -1955,7 +1950,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
buf = number(buf, end, (unsigned int)dn->phandle, num_spec); buf = number(buf, end, (unsigned int)dn->phandle, num_spec);
break; break;
case 'P': /* path-spec */ case 'P': /* path-spec */
p = kbasename(of_node_full_name(dn)); p = fwnode_get_name(of_fwnode_handle(dn));
if (!p[1]) if (!p[1])
p = "/"; p = "/";
buf = string(buf, end, p, str_spec); buf = string(buf, end, p, str_spec);