diff mbox series

[6/6] phy: core: Simplify API of_phy_simple_xlate() implementation

Message ID 20241020-phy_core_fix-v1-6-078062f7da71@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series phy: core: Fix bugs for several APIs and simplify an API | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 14 this patch: 14
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-20--12-00 (tests: 765)

Commit Message

Zijun Hu Oct. 20, 2024, 5:27 a.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

Simplify of_phy_simple_xlate() implementation by API
class_find_device_by_of_node() which is also safer since it
subsys_get() @phy_class subsystem firstly then iterates devices.

Also comment its parameter @dev with unused in passing since the parameter
provides no available input info but acts as an auto variable.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/phy/phy-core.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

Comments

Zijun Hu Oct. 20, 2024, 10:19 a.m. UTC | #1
On 2024/10/20 13:27, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Simplify of_phy_simple_xlate() implementation by API
> class_find_device_by_of_node() which is also safer since it
> subsys_get() @phy_class subsystem firstly then iterates devices.
> 
> Also comment its parameter @dev with unused in passing since the parameter
> provides no available input info but acts as an auto variable.
> 
i am not sure which parameter is unused. @dev or @args

comment says @args is not used here
but code actually uses @args but does not use @dev

> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/phy/phy-core.c | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 24bd619a33dd..102fc6b6ff71 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -748,7 +748,7 @@ EXPORT_SYMBOL_GPL(devm_phy_put);
>  
>  /**
>   * of_phy_simple_xlate() - returns the phy instance from phy provider
> - * @dev: the PHY provider device
> + * @dev: the PHY provider device unused
>   * @args: of_phandle_args (not used here)
>   *
>   * Intended to be used by phy provider for the common case where #phy-cells is
> @@ -759,20 +759,13 @@ 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) {
> +		put_device(target_dev);
> +		return to_phy(target_dev);
>  	}
> -
> -	class_dev_iter_exit(&iter);
>  	return ERR_PTR(-ENODEV);
>  }
>  EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
>
diff mbox series

Patch

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 24bd619a33dd..102fc6b6ff71 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -748,7 +748,7 @@  EXPORT_SYMBOL_GPL(devm_phy_put);
 
 /**
  * of_phy_simple_xlate() - returns the phy instance from phy provider
- * @dev: the PHY provider device
+ * @dev: the PHY provider device unused
  * @args: of_phandle_args (not used here)
  *
  * Intended to be used by phy provider for the common case where #phy-cells is
@@ -759,20 +759,13 @@  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) {
+		put_device(target_dev);
+		return to_phy(target_dev);
 	}
-
-	class_dev_iter_exit(&iter);
 	return ERR_PTR(-ENODEV);
 }
 EXPORT_SYMBOL_GPL(of_phy_simple_xlate);