[PATCH 7/9] device property: provide fwnode_property_count_references()
From: Bartosz Golaszewski
Date: Wed Nov 04 2026 - 09:11:01 EST
Provide fwnode_property_count_references() - a new fwnode function that
allows callers to retrieve the number of references in given property.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
drivers/base/property.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/property.h | 3 +++
2 files changed, 38 insertions(+)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 7b0df3dfae53b6377dba91330aac746684e8adec..259ecc4dc31a7b07e2ae5f53aa2424de54ba8236 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -654,6 +654,41 @@ int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
}
EXPORT_SYMBOL_GPL(fwnode_property_match_property_string);
+/**
+ * fwnode_property_count_references() - Count the references in a property
+ * @fwnode: Firmware node where to look for the property
+ * @prop: The name of the property
+ * @nargs_prop: The name of the property telling the number of arguments in the
+ * referred node. NULL if the references have no arguments.
+ *
+ * Empty references count too, so every index in the range [0, count) can be
+ * passed to fwnode_property_get_reference_args(), which may still fail for
+ * empty entries.
+ *
+ * Return: Number of references on success,
+ * %-ENOENT if the property was not found,
+ * %-EINVAL on parse error.
+ */
+int fwnode_property_count_references(const struct fwnode_handle *fwnode,
+ const char *prop, const char *nargs_prop)
+{
+ int ret;
+
+ if (IS_ERR_OR_NULL(fwnode))
+ return -ENOENT;
+
+ ret = fwnode_call_int_op(fwnode, count_references, prop, nargs_prop);
+ if (ret >= 0)
+ return ret;
+
+ if (IS_ERR_OR_NULL(fwnode->secondary))
+ return ret;
+
+ return fwnode_call_int_op(fwnode->secondary, count_references, prop,
+ nargs_prop);
+}
+EXPORT_SYMBOL_GPL(fwnode_property_count_references);
+
/**
* fwnode_property_get_reference_args() - Find a reference with arguments
* @fwnode: Firmware node where to look for the reference
diff --git a/include/linux/property.h b/include/linux/property.h
index a70f3c4c087dd85390951da950c3632f89c6cfd1..9f0b9aab5920513cd468572fa96dbe3371609591 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -137,6 +137,9 @@ int device_property_match_property_string(const struct device *dev,
return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n);
}
+int fwnode_property_count_references(const struct fwnode_handle *fwnode,
+ const char *prop, const char *nargs_prop);
+
int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
const char *prop, const char *nargs_prop,
unsigned int nargs, unsigned int index,
--
2.47.3