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.fat...@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 46328d12bcdf..0e6f75659f62 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


Reply via email to