[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <655e452d.5d0a0220.61c31.01ae@mx.google.com>
Date: Wed, 22 Nov 2023 19:15:06 +0100
From: Christian Marangi <ansuelsmth@...il.com>
To: Simon Horman <horms@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>, Andy Gross <agross@...nel.org>,
Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konrad.dybcio@...aro.org>,
Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
Florian Fainelli <florian.fainelli@...adcom.com>,
Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
Daniel Golle <daniel@...rotopia.org>,
Qingfang Deng <dqfext@...il.com>,
SkyLake Huang <SkyLake.Huang@...iatek.com>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
David Epping <david.epping@...singlinkelectronics.com>,
Vladimir Oltean <olteanv@...il.com>,
"Russell King (Oracle)" <rmk+kernel@...linux.org.uk>,
Harini Katakam <harini.katakam@....com>,
Robert Marko <robert.marko@...tura.hr>, netdev@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-msm@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org
Subject: Re: [net-next RFC PATCH 04/14] net: phy: add initial support for PHY
package in DT
On Wed, Nov 22, 2023 at 10:52:43AM +0000, Simon Horman wrote:
> On Mon, Nov 20, 2023 at 02:50:31PM +0100, Christian Marangi wrote:
> > Add initial support for PHY package in DT.
> >
> > Make it easier to define PHY package and describe the global PHY
> > directly in DT by refereincing them by phandles instead of custom
> > functions in each PHY driver.
> >
> > Each PHY in a package needs to be defined in a dedicated node in the
> > mdio node. This dedicated node needs to have the compatible set to
> > "ethernet-phy-package" and define "global-phys" and "#global-phy-cells"
> > respectively to a list of phandle to the global phy to define for the
> > PHY package and 0 for cells as the phandle won't take any args.
> >
> > With this defined, the generic PHY probe will join each PHY in this
> > dedicated node to the package.
> >
> > PHY driver MUST set the required global PHY count in
> > .phy_package_global_phy_num to correctly verify that DT define the
> > correct number of phandle to the required global PHY.
> >
> > mdio_bus.c and of_mdio.c is updated to now support and parse also
> > PHY package subnote that have the compatible "phy-package".
> >
> > Signed-off-by: Christian Marangi <ansuelsmth@...il.com>
>
> Hi Christian,
>
> I was a little hasty in hitting send on my previous message.
> Please find some more minor feedback from my side below.
>
Thanks a lot for the initial review and sorry for the various warning
you had to write about it. I know this was a new concept and that I had
to discuss a lot about the DT structure so I was a bit relaxed in
releasing OF node. Will handle all of them in v2. Again thanks!
> ...
>
> > diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c
> > index 64ebcb6d235c..bb910651118f 100644
> > --- a/drivers/net/mdio/of_mdio.c
> > +++ b/drivers/net/mdio/of_mdio.c
> > @@ -139,6 +139,44 @@ bool of_mdiobus_child_is_phy(struct device_node *child)
> > }
> > EXPORT_SYMBOL(of_mdiobus_child_is_phy);
> >
> > +static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np,
> > + bool *scanphys)
> > +{
> > + struct device_node *child;
> > + int addr, rc;
> > +
> > + /* Loop over the child nodes and register a phy_device for each phy */
> > + for_each_available_child_of_node(np, child) {
> > + if (of_device_is_compatible(child, "ethernet-phy-package")) {
> > + rc = __of_mdiobus_parse_phys(mdio, child, scanphys);
> > + if (rc && rc != -ENODEV)
> > + return rc;
>
> for_each_available_child_of_node() makes calls to of_node_get() and
> of_node_put(), so when jumping out of a loop it is necessary to call
> of_node_put(), in this case of_node_put(child).
>
> As flagged by Coccinelle.
>
> Also flagged in of_mdiobus_find_phy() both before and after this patch.
>
> > +
> > + continue;
> > + }
> > +
> > + addr = of_mdio_parse_addr(&mdio->dev, child);
> > + if (addr < 0) {
> > + *scanphys = true;
> > + continue;
> > + }
> > +
> > + if (of_mdiobus_child_is_phy(child))
> > + rc = of_mdiobus_register_phy(mdio, child, addr);
> > + else
> > + rc = of_mdiobus_register_device(mdio, child, addr);
> > +
> > + if (rc == -ENODEV)
> > + dev_err(&mdio->dev,
> > + "MDIO device at address %d is missing.\n",
> > + addr);
> > + else if (rc)
> > + return rc;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > /**
> > * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
> > * @mdio: pointer to mii_bus structure
> > @@ -180,25 +218,9 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
> > return rc;
> >
> > /* Loop over the child nodes and register a phy_device for each phy */
> > - for_each_available_child_of_node(np, child) {
> > - addr = of_mdio_parse_addr(&mdio->dev, child);
> > - if (addr < 0) {
> > - scanphys = true;
> > - continue;
> > - }
> > -
> > - if (of_mdiobus_child_is_phy(child))
> > - rc = of_mdiobus_register_phy(mdio, child, addr);
> > - else
> > - rc = of_mdiobus_register_device(mdio, child, addr);
> > -
> > - if (rc == -ENODEV)
> > - dev_err(&mdio->dev,
> > - "MDIO device at address %d is missing.\n",
> > - addr);
> > - else if (rc)
> > - goto unregister;
> > - }
> > + rc = __of_mdiobus_parse_phys(mdio, np, &scanphys);
> > + if (rc)
> > + goto unregister;
>
> Jumping to unregister will call of_node_put(child),
> however child appears to be uninitialised here.
>
> Flagged by clang-16 W=1 build, and Smatch.
>
> >
> > if (!scanphys)
> > return 0;
>
> ...
--
Ansuel
Powered by blists - more mailing lists