lkml.org 
[lkml]   [2021]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v4 net-next 15/23] device property: add helper function fwnode_get_child_node_count
Date
Functions existed for determining the node count by device, but not by
fwnode_handle. In the case where a driver could either be defined as a
standalone device or a node of a different device, parsing from the root of
the device might not make sense. As such, it becomes necessary to parse
from a child node instead of the device root node.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
drivers/base/property.c | 20 ++++++++++++++++----
include/linux/property.h | 1 +
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index f1f35b48ab8b..2ee675e1529d 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -845,19 +845,31 @@ bool fwnode_device_is_available(const struct fwnode_handle *fwnode)
EXPORT_SYMBOL_GPL(fwnode_device_is_available);

/**
- * device_get_child_node_count - return the number of child nodes for device
- * @dev: Device to cound the child nodes for
+ * fwnode_get_child_node_count - return the number of child nodes for the fwnode
+ * @fwnode: Node to count the childe nodes for
*/
-unsigned int device_get_child_node_count(struct device *dev)
+unsigned int fwnode_get_child_node_count(struct fwnode_handle *fwnode)
{
struct fwnode_handle *child;
unsigned int count = 0;

- device_for_each_child_node(dev, child)
+ fwnode_for_each_child_node(fwnode, child)
count++;

return count;
}
+EXPORT_SYMBOL_GPL(fwnode_get_child_node_count);
+
+/**
+ * device_get_child_node_count - return the number of child nodes for device
+ * @dev: Device to count the child nodes for
+ */
+unsigned int device_get_child_node_count(struct device *dev)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+ return fwnode_get_child_node_count(fwnode);
+}
EXPORT_SYMBOL_GPL(device_get_child_node_count);

bool device_dma_supported(struct device *dev)
diff --git a/include/linux/property.h b/include/linux/property.h
index 88fa726a76df..6dc71029cfc5 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -122,6 +122,7 @@ void fwnode_handle_put(struct fwnode_handle *fwnode);

int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);

+unsigned int fwnode_get_child_node_count(struct fwnode_handle *fwnode);
unsigned int device_get_child_node_count(struct device *dev);

static inline bool device_property_read_bool(struct device *dev,
--
2.25.1
\
 
 \ /
  Last update: 2021-11-16 07:29    [W:0.190 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site