Thread (27 messages) 27 messages, 5 authors, 2021-06-11

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

From: "Rafael J. Wysocki" <rafael@kernel.org>
Date: 2021-06-11 11:41:28
Also in: linux-acpi, lkml, netdev

On Fri, Jun 11, 2021 at 1:26 PM Andy Shevchenko
[off-list ref] wrote:
On Fri, Jun 11, 2021 at 1:54 PM Ioana Ciornei [off-list ref] wrote:
quoted
From: Calvin Johnson <redacted>

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

...
quoted
+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);
quoted
+}
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help