From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Jonathan Cameron <jic23@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Claudiu Manoil <claudiu.manoil@nxp.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH v5 02/10] property: Add functions to count named child nodes
Date: Mon, 3 Mar 2025 13:50:13 +0200 [thread overview]
Message-ID: <Z8WXdf8lnivYKiks@kuha.fi.intel.com> (raw)
In-Reply-To: <5e35f44db2b4ed43f75c4c53fd0576df9ad24ab2.1740993491.git.mazziesaccount@gmail.com>
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
next prev parent reply other threads:[~2025-03-03 11:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 11:30 [PATCH v5 00/10] Support ROHM BD79124 ADC Matti Vaittinen
2025-03-03 11:31 ` [PATCH v5 02/10] property: Add functions to count named child nodes Matti Vaittinen
2025-03-03 11:50 ` Heikki Krogerus [this message]
2025-03-03 12:00 ` Andy Shevchenko
2025-03-03 11:59 ` Andy Shevchenko
2025-03-10 6:23 ` Matti Vaittinen
2025-03-10 8:23 ` Andy Shevchenko
2025-03-03 11:32 ` [PATCH v5 03/10] iio: adc: add helpers for parsing ADC nodes Matti Vaittinen
2025-03-04 9:25 ` David Lechner
2025-03-04 12:07 ` Andy Shevchenko
2025-03-05 10:54 ` Matti Vaittinen
2025-03-08 16:29 ` Jonathan Cameron
2025-03-10 7:41 ` Matti Vaittinen
2025-03-10 19:25 ` Jonathan Cameron
2025-03-03 11:34 ` [PATCH v5 08/10] MAINTAINERS: Add IIO ADC helpers Matti Vaittinen
2025-03-03 11:34 ` [PATCH RFC net-next v5 10/10] net: gianfar: Use device_get_child_node_count_named() Matti Vaittinen
2025-03-03 11:51 ` Andy Shevchenko
2025-03-03 12:13 ` Matti Vaittinen
2025-03-03 12:24 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z8WXdf8lnivYKiks@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=andriy.shevchenko@linux.intel.com \
--cc=claudiu.manoil@nxp.com \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=djrscally@gmail.com \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox