[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGETcx93J_gpTLhANbjfiBrZ=PCN4bUabfHGG-jv0KdfOUMyjg@mail.gmail.com>
Date: Tue, 24 Aug 2021 12:34:33 -0700
From: Saravana Kannan <saravanak@...gle.com>
To: Pavel Machek <pavel@...x.de>
Cc: Sasha Levin <sashal@...nel.org>, linux-kernel@...r.kernel.org,
stable@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
Marc Zyngier <maz@...nel.org>,
Kevin Hilman <khilman@...libre.com>,
"David S . Miller" <davem@...emloft.net>
Subject: Re: [PATCH 5.10 64/98] net: mdio-mux: Handle -EPROBE_DEFER correctly
On Tue, Aug 24, 2021 at 12:00 PM Pavel Machek <pavel@...x.de> wrote:
>
> Hi1
>
> > When registering mdiobus children, if we get an -EPROBE_DEFER, we shouldn't
> > ignore it and continue registering the rest of the mdiobus children. This
> > would permanently prevent the deferring child mdiobus from working instead
> > of reattempting it in the future. So, if a child mdiobus needs to be
> > reattempted in the future, defer the entire mdio-mux initialization.
> >
> > This fixes the issue where PHYs sitting under the mdio-mux aren't
> > initialized correctly if the PHY's interrupt controller is not yet ready
> > when the mdio-mux is being probed. Additional context in the link
> > below.
>
> I don't believe this is quite right. AFAICT it leaks memory in the
> EPROBE_DEFER case. Could someone double-check? Suggested fix is below.
devm_ APIs would take care of releasing the resource (memory)
automatically because the probe didn't succeed. So I'm not sure
there's a leak. Does that make sense?
-Saravana
>
> > +++ b/drivers/net/mdio/mdio-mux.c
> > @@ -175,11 +175,15 @@ int mdio_mux_init(struct device *dev,
> > cb->mii_bus->write = mdio_mux_write;
> > r = of_mdiobus_register(cb->mii_bus, child_bus_node);
> > if (r) {
> > + mdiobus_free(cb->mii_bus);
> > + if (r == -EPROBE_DEFER) {
> > + ret_val = r;
> > + goto err_loop;
> > + }
> > + devm_kfree(dev, cb);
> > dev_err(dev,
> > "Error: Failed to register MDIO bus for child %pOF\n",
> > child_bus_node);
> > - mdiobus_free(cb->mii_bus);
> > - devm_kfree(dev, cb);
> > } else {
> > cb->next = pb->children;
> > pb->children = cb;
>
>
> Signed-off-by: Pavel Machek (CIP) <pavel@...x.de>
>
> diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c
> index ccb3ee704eb1..6d0e505343c5 100644
> --- a/drivers/net/mdio/mdio-mux.c
> +++ b/drivers/net/mdio/mdio-mux.c
> @@ -163,6 +163,7 @@ int mdio_mux_init(struct device *dev,
> cb->mii_bus = mdiobus_alloc();
> if (!cb->mii_bus) {
> ret_val = -ENOMEM;
> + devm_kfree(dev, cb);
> goto err_loop;
> }
> cb->mii_bus->priv = cb;
> @@ -176,11 +177,11 @@ int mdio_mux_init(struct device *dev,
> r = of_mdiobus_register(cb->mii_bus, child_bus_node);
> if (r) {
> mdiobus_free(cb->mii_bus);
> + devm_kfree(dev, cb);
> if (r == -EPROBE_DEFER) {
> ret_val = r;
> goto err_loop;
> }
> - devm_kfree(dev, cb);
> dev_err(dev,
> "Error: Failed to register MDIO bus for child %pOF\n",
> child_bus_node);
>
>
> --
> DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Powered by blists - more mailing lists