Re: [PATCH net-next v9 03/15] net: phy: Introduce phy related fwnode functions

From: Andy Shevchenko
Date: Fri Jun 11 2021 - 07:27:46 EST


On Fri, Jun 11, 2021 at 1:54 PM Ioana Ciornei <ciorneiioana@xxxxxxxxx> wrote:
>
> From: Calvin Johnson <calvin.johnson@xxxxxxxxxxx>
>
> Define fwnode_phy_find_device() to iterate an mdiobus and find the
> phy device of the provided phy fwnode. Additionally define
> device_phy_find_device() to find phy device of provided device.
>
> Define fwnode_get_phy_node() to get phy_node using named reference.

using a named

...

> +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode)
> +{
> + struct fwnode_handle *phy_node;
> +
> + /* Only phy-handle is used for ACPI */
> + phy_node = fwnode_find_reference(fwnode, "phy-handle", 0);
> + if (is_acpi_node(fwnode) || !IS_ERR(phy_node))
> + return phy_node;
> + phy_node = fwnode_find_reference(fwnode, "phy", 0);
> + if (IS_ERR(phy_node))
> + phy_node = fwnode_find_reference(fwnode, "phy-device", 0);
> + return phy_node;

Looking into the patterns in this code I would perhaps refactor it the
following way:

/* First try "phy-handle" as most common in use */
phy_node = fwnode_find_reference(fwnode, "phy-handle", 0);
/* Only phy-handle is used for ACPI */
if (is_acpi_node(fwnode))
return phy_node;
if (!IS_ERR(phy_node))
return phy_node;
/* Try "phy" reference */
phy_node = fwnode_find_reference(fwnode, "phy", 0);
if (!IS_ERR(phy_node))
return phy_node;
/* At last try "phy-device" reference */
return fwnode_find_reference(fwnode, "phy-device", 0);

> +}


--
With Best Regards,
Andy Shevchenko