[PATCH 1/2] driver core: provide device_match_fwnode_ext()

From: Bartosz Golaszewski

Date: Thu Feb 19 2026 - 11:32:00 EST


Provide an extended variant of device_match_fwnode() that also tries to
match the device's secondary fwnode.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
drivers/base/core.c | 14 ++++++++++++++
include/linux/device/bus.h | 1 +
2 files changed, 15 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index f599a1384eec90c104601422b04dc2b4c19d4382..bbf1337978fafc35eb94bda85e0bb7f6879879c0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -5326,6 +5326,20 @@ int device_match_fwnode(struct device *dev, const void *fwnode)
}
EXPORT_SYMBOL_GPL(device_match_fwnode);

+int device_match_fwnode_ext(struct device *dev, const void *fwnode)
+{
+ struct fwnode_handle *dev_node = dev_fwnode(dev);
+
+ if (!fwnode)
+ return 0;
+
+ if (dev_node == fwnode)
+ return 1;
+
+ return fwnode_is_primary(dev_node) && dev_node->secondary == fwnode;
+}
+EXPORT_SYMBOL_GPL(device_match_fwnode_ext);
+
int device_match_devt(struct device *dev, const void *pdevt)
{
return dev->devt == *(dev_t *)pdevt;
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index 99c3c83ea520876ab3577ffa76f159f89f4f86c5..bb6ed08c39aee497feabdba82d2e8f89ca1c8b5f 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -137,6 +137,7 @@ int device_match_name(struct device *dev, const void *name);
int device_match_type(struct device *dev, const void *type);
int device_match_of_node(struct device *dev, const void *np);
int device_match_fwnode(struct device *dev, const void *fwnode);
+int device_match_fwnode_ext(struct device *dev, const void *fwnode);
int device_match_devt(struct device *dev, const void *pdevt);
int device_match_acpi_dev(struct device *dev, const void *adev);
int device_match_acpi_handle(struct device *dev, const void *handle);

--
2.47.3