On Wed, Jul 11, 2018 at 10:04 PM Andrew Lunn <and...@lunn.ch> wrote:

> What probably make sense as a followup is add a
> of_phy_disconnect_and_put(). When the module is unloaded, you leak a
> fixed link, because of_phy_deregister_fixed_link() is not being
> called.

I looked at this but I get a bit confused. How to handle
cleanup of the fixed link is pretty straight forward, I'm more
concerned with the proper (today non-existing) way to clean
up after of_phy_connect() that is called for all instances.

This calls phy_connect_direct() that then does this:

/* refcount is held by phy_connect_direct() on success */
put_device(&phy->mdio.dev);

Which seems like wrong - it should keep holding that until
we do of_phy_disconnect_and_put() in that case.
The above seems like some hack, i.e. we are using the
MDIO without holding a reference or something, so it
can go away cleanly later.

Or do I have it wrong?

It's confusing, I guess these PHY's don't come and go
very much so the plug/play part isn't really exercised.

> You also hold a reference to np which does not appear to be
> released.

That seems to be covered as there is a of_node_put(phy_np);
at the end of this function already.

Balancing of_node_get()/put() is another area where there
is not (AFAICT) much stringency in the kernel. I loosely
believe this is mostly for dynamic device trees (so you do not
delete a node that is in use e.g.) and people don't use that
very much (or at all). I think most systems shut down with
a bunch of OF nodes held. :/

(Yeah another universe of cleanups the day we need it
to work.)

Yours,
Linus Walleij

Reply via email to