Re: [PATCH v5 02/10] property: Add functions to count named child nodes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

> +/**
> + * fwnode_get_child_node_count_named - number of child nodes with given name
> + * @fwnode: Node which child nodes are counted.
> + * @name: String to match child node name against.
> + *
> + * Scan child nodes and count all the nodes with a specific name. Return the
> + * number of found nodes. Potential '@number' -ending for scanned names is
> + * ignored. Eg,
> + * device_get_child_node_count(dev, "channel");
> + * would match all the nodes:
> + * channel { }, channel@0 {}, channel@0xabba {}...
> + *
> + * Return: the number of child nodes with a matching name for a given device.
> + */
> +unsigned int fwnode_get_child_node_count_named(const struct fwnode_handle *fwnode,
> +					       const char *name)
> +{
> +	struct fwnode_handle *child;
> +	unsigned int count = 0;
> +
> +	fwnode_for_each_child_node(fwnode, child)
> +		if (fwnode_name_eq(child, name))
> +			count++;
> +
> +	return count;
> +}
> +EXPORT_SYMBOL_GPL(fwnode_get_child_node_count_named);
> +
> +/**
> + * device_get_child_node_count_named - number of child nodes with given name
> + * @dev: Device to count the child nodes for.
> + * @name: String to match child node name against.
> + *
> + * Scan device's child nodes and find all the nodes with a specific name and
> + * return the number of found nodes. Potential '@number' -ending for scanned
> + * names is ignored. Eg,
> + * device_get_child_node_count(dev, "channel");
> + * would match all the nodes:
> + * channel { }, channel@0 {}, channel@0xabba {}...
> + *
> + * Return: the number of child nodes with a matching name for a given device.
> + */
> +unsigned int device_get_child_node_count_named(const struct device *dev,
> +					       const char *name)
> +{
> +	const struct fwnode_handle *fwnode = dev_fwnode(dev);
> +
> +	if (!fwnode)
> +		return -EINVAL;
> +
> +	if (IS_ERR(fwnode))
> +		return PTR_ERR(fwnode);
> +
> +	return fwnode_get_child_node_count_named(fwnode, name);
> +}
> +EXPORT_SYMBOL_GPL(device_get_child_node_count_named);

Sorry if I missed something in the v4 thread, but why not do all the
checks in fwnode_get_child_node_count_named(), and make this an inline
function?

        static inline unsigned int
        device_get_child_node_count_named(const struct device *dev, const char *name)
        {
                return fwnode_get_child_node_count_named(dev_fwnode(fwnode), name);
        }

thanks,

-- 
heikki




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux