[PATCH net-next v9 03/15] net: phy: Introduce phy related fwnode functions
Rafael J. Wysocki
rafael at kernel.org
Fri Jun 11 04:40:59 PDT 2021
On Fri, Jun 11, 2021 at 1:26 PM Andy Shevchenko
<andy.shevchenko at gmail.com> wrote:
>
> On Fri, Jun 11, 2021 at 1:54 PM Ioana Ciornei <ciorneiioana at gmail.com> wrote:
> >
> > From: Calvin Johnson <calvin.johnson at oss.nxp.com>
> >
> > 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;
I'm not sure why you want the above to be two if () statements instead of one?
I would change the ordering anyway, that is
if (!IS_ERR(phy_node) || is_acpi_node(fwnode))
return phy_node;
And I think that the is_acpi_node() check is there to return the error
code right away so as to avoid returning a "not found" error later.
But I'm not sure if this is really necessary. Namely, if nothing
depends on the specific error code returned by this function, it would
be somewhat cleaner to let the code below run if phy_node is an error
pointer in the ACPI case, because in that case the code below will
produce an error pointer anyway.
> /* 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);
>
> > +}
More information about the linux-arm-kernel
mailing list