diff options
author | Sakari Ailus <sakari.ailus@linux.intel.com> | 2019-10-03 14:32:13 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2019-10-11 11:26:55 +0200 |
commit | e7e242bccb209b5f73455b33928b8680cc6e3319 (patch) | |
tree | 71ab6dcb21967662c41dae3fd869b421f5775b60 /drivers/base/swnode.c | |
parent | device property: Add fwnode_get_name for returning the name of a node (diff) | |
download | linux-e7e242bccb209b5f73455b33928b8680cc6e3319.tar.xz linux-e7e242bccb209b5f73455b33928b8680cc6e3319.zip |
device property: Add a function to obtain a node's prefix
The prefix is used for printing purpose before a node, and it also works
as a separator between two nodes.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Rob Herring <robh@kernel.org> (for OF)
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/base/swnode.c')
-rw-r--r-- | drivers/base/swnode.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index eacca6a6626b..12ca439bab30 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -526,6 +526,27 @@ software_node_get_name(const struct fwnode_handle *fwnode) return kobject_name(&swnode->kobj); } +static const char * +software_node_get_name_prefix(const struct fwnode_handle *fwnode) +{ + struct fwnode_handle *parent; + const char *prefix; + + parent = fwnode_get_parent(fwnode); + if (!parent) + return ""; + + /* Figure out the prefix from the parents. */ + while (is_software_node(parent)) + parent = fwnode_get_next_parent(parent); + + prefix = fwnode_get_name_prefix(parent); + fwnode_handle_put(parent); + + /* Guess something if prefix was NULL. */ + return prefix ?: "/"; +} + static struct fwnode_handle * software_node_get_parent(const struct fwnode_handle *fwnode) { @@ -627,6 +648,7 @@ static const struct fwnode_operations software_node_ops = { .property_read_int_array = software_node_read_int_array, .property_read_string_array = software_node_read_string_array, .get_name = software_node_get_name, + .get_name_prefix = software_node_get_name_prefix, .get_parent = software_node_get_parent, .get_next_child_node = software_node_get_next_child, .get_named_child_node = software_node_get_named_child_node, |