[PATCH 05/16] drive: bus: make use of new bus_find_device helper

Ahmad Fatoum a.fatoum at barebox.org
Thu Jun 5 14:07:15 PDT 2025


Instead of opencoding the iteration, let's make use of the new
helpers to lookup devices on a given bus.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/efi/efi-device.c | 17 ++++++++++-------
 drivers/net/phy/phy.c    |  7 +++----
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index d5eda66cd55a..23fcef7957fe 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -30,17 +30,20 @@ static int efi_locate_handle(enum efi_locate_search_type search_type,
 				   buffer);
 }
 
+static int efi_device_match_handle(struct device *dev, const void *handle)
+{
+	struct efi_device *efidev = container_of(dev, struct efi_device, dev);
+	return efidev->handle == handle;
+}
+
 static struct efi_device *efi_find_device(efi_handle_t handle)
 {
 	struct device *dev;
-	struct efi_device *efidev;
 
-	bus_for_each_device(&efi_bus, dev) {
-		efidev = container_of(dev, struct efi_device, dev);
-
-		if (efidev->handle == handle)
-			return efidev;
-	}
+	dev = bus_find_device(&efi_bus, NULL, efi_device_match_handle,
+			      efi_device_match_handle);
+	if (dev)
+		return container_of(dev, struct efi_device, dev);
 
 	return NULL;
 }
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d9f50f45f441..9635c816c330 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -374,10 +374,9 @@ static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
 		}
 	}
 
-	bus_for_each_device(&mdio_bus_type, dev) {
-		if (dev->of_node == phy_node)
-			return container_of(dev, struct phy_device, dev);
-	}
+	dev = bus_find_device_by_of_node(&mdio_bus_type, phy_node);
+	if (dev)
+		return container_of(dev, struct phy_device, dev);
 
 	return NULL;
 }
-- 
2.39.5




More information about the barebox mailing list