]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
phy: core: Simplify API of_phy_simple_xlate() implementation
authorZijun Hu <quic_zijuhu@quicinc.com>
Fri, 13 Dec 2024 12:36:46 +0000 (20:36 +0800)
committerVinod Koul <vkoul@kernel.org>
Tue, 24 Dec 2024 14:25:59 +0000 (19:55 +0530)
Simplify of_phy_simple_xlate() implementation by API
class_find_device_by_of_node().

Also correct comments to mark its parameter @dev as unused instead of
@args in passing.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Cc: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20241213-phy_core_fix-v6-6-40ae28f5015a@quicinc.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/phy/phy-core.c

index f053b525ccffab1629f5e09581a6ebcc35e47f79..cee4be2708109e267d9820e8a58324365e51fd8f 100644 (file)
@@ -744,8 +744,8 @@ EXPORT_SYMBOL_GPL(devm_phy_put);
 
 /**
  * of_phy_simple_xlate() - returns the phy instance from phy provider
- * @dev: the PHY provider device
- * @args: of_phandle_args (not used here)
+ * @dev: the PHY provider device (not used here)
+ * @args: of_phandle_args
  *
  * Intended to be used by phy provider for the common case where #phy-cells is
  * 0. For other cases where #phy-cells is greater than '0', the phy provider
@@ -755,21 +755,14 @@ EXPORT_SYMBOL_GPL(devm_phy_put);
 struct phy *of_phy_simple_xlate(struct device *dev,
                                const struct of_phandle_args *args)
 {
-       struct phy *phy;
-       struct class_dev_iter iter;
-
-       class_dev_iter_init(&iter, &phy_class, NULL, NULL);
-       while ((dev = class_dev_iter_next(&iter))) {
-               phy = to_phy(dev);
-               if (args->np != phy->dev.of_node)
-                       continue;
+       struct device *target_dev;
 
-               class_dev_iter_exit(&iter);
-               return phy;
-       }
+       target_dev = class_find_device_by_of_node(&phy_class, args->np);
+       if (!target_dev)
+               return ERR_PTR(-ENODEV);
 
-       class_dev_iter_exit(&iter);
-       return ERR_PTR(-ENODEV);
+       put_device(target_dev);
+       return to_phy(target_dev);
 }
 EXPORT_SYMBOL_GPL(of_phy_simple_xlate);