Message ID | 20211116062328.1949151-16-colin.foster@in-advantage.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | add support for VSC75XX control over SPI | expand |
On Mon, Nov 15, 2021 at 10:23:20PM -0800, Colin Foster wrote: > 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); You can now make device_get_child_node_count() an inline function: static inline unsigned int device_get_child_node_count(struct device *dev) { return fwnode_get_child_node_count(dev_fwnode(dev)); } thanks,
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,
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(-)