[PATCH v3 04/14] software node: Add software_node_match_device() API

From: Manivannan Sadhasivam via B4 Relay

Date: Sat Jan 10 2026 - 01:57:05 EST


From: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>

Add software_node_match_device() API to match the swnode device with the
swnode driver. The matching is based on the compatible property in the
device and the driver's of_match_table.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
---
drivers/base/swnode.c | 16 ++++++++++++++++
include/linux/property.h | 3 +++
2 files changed, 19 insertions(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index cd722712b8e9..4a3b367dea02 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -372,6 +372,22 @@ void property_entries_free(const struct property_entry *properties)
}
EXPORT_SYMBOL_GPL(property_entries_free);

+bool software_node_match_device(struct device *dev, const struct device_driver *drv)
+{
+ const struct of_device_id *id;
+
+ if (!drv->of_match_table)
+ return false;
+
+ for (id = drv->of_match_table; id->compatible[0]; id++) {
+ if (device_is_compatible(dev, id->compatible))
+ return true;
+ }
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(software_node_match_device);
+
/* -------------------------------------------------------------------------- */
/* fwnode operations */

diff --git a/include/linux/property.h b/include/linux/property.h
index 272bfbdea7bf..7fe75ab732f6 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -14,6 +14,7 @@
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/cleanup.h>
+#include <linux/device.h>
#include <linux/fwnode.h>
#include <linux/stddef.h>
#include <linux/types.h>
@@ -597,6 +598,8 @@ void software_node_unregister_node_group(const struct software_node * const *nod
int software_node_register(const struct software_node *node);
void software_node_unregister(const struct software_node *node);

+bool software_node_match_device(struct device *dev, const struct device_driver *drv);
+
struct fwnode_handle *
fwnode_create_software_node(const struct property_entry *properties,
const struct fwnode_handle *parent);

--
2.48.1