Thread (12 messages) 12 messages, 3 authors, 2020-07-10

Re: [net-next PATCH v4 4/6] net: phy: introduce phy_find_by_fwnode()

From: Andy Shevchenko <hidden>
Date: 2020-07-09 20:44:03
Also in: linux-acpi

On Thu, Jul 9, 2020 at 8:57 PM Calvin Johnson
[off-list ref] wrote:
The PHYs on an mdiobus are probed and registered using mdiobus_register().
Later, for connecting these PHYs to MAC, the PHYs registered on the
mdiobus have to be referenced.

For each MAC node, a property "mdio-handle" is used to reference the
MDIO bus on which the PHYs are registered. On getting hold of the MDIO
bus, use phy_find_by_fwnode() to get the PHY connected to the MAC.

Introduce fwnode_mdio_find_bus() to find the mii_bus that corresponds
to given mii_bus fwnode.
...
+struct phy_device *phy_find_by_fwnode(struct fwnode_handle *fwnode)
+{
+       struct fwnode_handle *fwnode_mdio;
+       struct mii_bus *mdio;
+       int addr;
+       int err;
+
+       fwnode_mdio = fwnode_find_reference(fwnode, "mdio-handle", 0);
+       mdio = fwnode_mdio_find_bus(fwnode_mdio);
+       fwnode_handle_put(fwnode_mdio);
+       if (!mdio)
+               return ERR_PTR(-ENODEV);
+       err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
+       if (err < 0 || addr < 0 || addr >= PHY_MAX_ADDR)
+               return ERR_PTR(-EINVAL);
I'm wondering why this is written like above and not like below

err = ...
if (err)
  return ERR_PTR(err);
if (...)
 return ERR_PTR(-E...);

?
+       return mdiobus_get_phy(mdio, addr);
+}
-- 
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help