Re: [PATCH v4 02/10] property: Add device_get_child_node_count_named()

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

 



On 25/02/2025 11:40, Heikki Krogerus wrote:
Hi,

+/**
+ * device_get_child_node_count_named - number of child nodes with given name
+ *
+ * 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 {}...
+ *
+ * @dev: Device to count the child nodes for
+ *
+ * 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)
+{
+	struct fwnode_handle *child;
+	unsigned int count = 0;
+
+	device_for_each_child_node(dev, child)
+		if (fwnode_name_eq(child, "channel"))

s/"channel"/name/ ?

Thanks Heikki for spotting this brainfart! :)


+			count++;
+
+	return count;
+}
+EXPORT_SYMBOL_GPL(device_get_child_node_count_named);

I did not check how many users are you proposing for this, but if
there's only one, then IMO this should not be a global function yet.

I have no strong opinion on this. It starts with just 1 user (IIO ADC channel stuff), but I've a feeling there are other areas which do look-up nodes by name. I suppose "channels" are looked-up in other areas of IIO as well. Lookups are probably done outside the IIO as well. I haven't audited this, but I wouldn't be surprized if at least LEDs (and perhaps clks/regulators?) could find this useful too.

It just feels to special case to me. But let's see what the others
think.

Yeah :) And thanks for spotting the "channel" -thing :)

Yours,
	-- Matti




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux