Re: [PATCH v2 2/4] phy: core: Add common helper for get phy phandle by index

From: Vladimir Oltean

Date: Mon Sep 07 2026 - 07:38:47 EST


On Fri, Sep 04, 2026 at 04:37:06PM +0800, Inochi Amaoto wrote:
> Several phy helper use index to get phy phandle of a device node,
> add a common function for the future reuse.
>
> Signed-off-by: Inochi Amaoto <inochiama@xxxxxxxxx>
> ---
> drivers/phy/phy-core.c | 51 +++++++++++++++++++++++++-----------------
> 1 file changed, 30 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ea79913fbb87..a7d7acb5d3c2 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -681,33 +681,49 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
> return phy;
> }
>
> +/**
> + * of_phy_get_by_index() - lookup and obtain a reference to a phy using a
> + * device_node by index.
> + * @np: device_node for which to get the phy
> + * @index: index of the phy from device's point of view
> + *
> + * Returns: the phy driver, after getting a refcount to it; or

Not driver, but device.

> + * -ENODEV if there is no such phy. The caller is responsible for
> + * calling of_phy_put() to release that count.
> + */
> +static struct phy *of_phy_get_by_index(struct device_node *np, int index)
> +{
> + struct phy *phy;
> +
> + phy = _of_phy_get(np, index);
> + if (IS_ERR(phy))
> + return phy;
> +
> + if (!try_module_get(phy->ops->owner))
> + return ERR_PTR(-EPROBE_DEFER);
> +
> + get_device(&phy->dev);
> +
> + return phy;
> +}
> +
> /**
> * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
> * @np: device_node for which to get the phy
> * @con_id: name of the phy from device's point of view
> *
> - * Returns the phy driver, after getting a refcount to it; or
> + * Returns: the phy driver, after getting a refcount to it; or

Same comment here. You are changing this line anyway.

> * -ENODEV if there is no such phy. The caller is responsible for
> * calling of_phy_put() to release that count.
> */
> struct phy *of_phy_get(struct device_node *np, const char *con_id)
> {
> - struct phy *phy = NULL;
> int index = 0;
>
> if (con_id)
> index = of_property_match_string(np, "phy-names", con_id);
>
> - phy = _of_phy_get(np, index);
> - if (IS_ERR(phy))
> - return phy;
> -
> - if (!try_module_get(phy->ops->owner))
> - return ERR_PTR(-EPROBE_DEFER);
> -
> - get_device(&phy->dev);
> -
> - return phy;
> + return of_phy_get_by_index(np, index);
> }
> EXPORT_SYMBOL_GPL(of_phy_get);
>
> @@ -957,7 +973,7 @@ EXPORT_SYMBOL_GPL(devm_of_phy_optional_get);
> * @np: node containing the phy
> * @index: index of the phy
> *
> - * Gets the phy using _of_phy_get(), then gets a refcount to it,
> + * Gets the phy using of_phy_get_by_index(), then gets a refcount to it,
> * and associates a device with it using devres. On driver detach,
> * release function is invoked on the devres data,
> * then, devres data is freed.
> @@ -972,19 +988,12 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
> if (!ptr)
> return ERR_PTR(-ENOMEM);
>
> - phy = _of_phy_get(np, index);
> + phy = of_phy_get_by_index(np, index);
> if (IS_ERR(phy)) {
> devres_free(ptr);
> return phy;
> }
>
> - if (!try_module_get(phy->ops->owner)) {
> - devres_free(ptr);
> - return ERR_PTR(-EPROBE_DEFER);
> - }
> -
> - get_device(&phy->dev);
> -
> *ptr = phy;
> devres_add(dev, ptr);
>
> --
> 2.55.0
>
>