Netdev List
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: "Alvin Šipraga" <ALSI@bang-olufsen.dk>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linus.walleij@linaro.org" <linus.walleij@linaro.org>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"arinc.unal@arinc9.com" <arinc.unal@arinc9.com>
Subject: Re: [PATCH net-next 2/7] net: dsa: realtek: put of node after MDIO registration
Date: Mon, 11 Dec 2023 19:11:43 +0200	[thread overview]
Message-ID: <20231211171143.yrvtw7l6wihkbeur@skbuf> (raw)
In-Reply-To: <CAJq09z45WQv-F9dw-y13E_6DXAfmpxH20JnRoO10za3cuS2kZw@mail.gmail.com>

On Fri, Dec 08, 2023 at 03:05:41PM -0300, Luiz Angelo Daros de Luca wrote:
> Reviewing the code again, I believe it was not just misplacing the
> of_put_node() but probably calling it twice.
> 
> devm_mdiobus_alloc() doesn't set the dev in mii_bus. So, dev is all
> zeros. The dev.of_node normal place to be defined is:
> 
> devm_of_mdiobus_register()
>   __devm_of_mdiobus_register()
>     __of_mdiobus_register()
>       device_set_node()
> 
> The only way for that value, set by the line I removed, to persist is
> when the devm_of_mdiobus_register() fails before device_set_node().

Did you consider that __of_mdiobus_register() -> device_set_node() is
actually overwriting priv->user_mii_bus->dev.of_node with the same value?
So the reference to mdio_np persists even if technically overwritten.
The fact that the assignment looks redundant is another story.

> My guess is that it was set to be used by realtek_smi_remove() if it
> is called when registration fails. However, in that case, both
> realtek_smi_setup_mdio() and realtek_smi_setup_mdio() would put the

You listed the same function name twice. You meant realtek_smi_remove()
the second time?

> node. So, either the line is useless or it will effectively result in
> calling of_node_put() twice.

False logic, since realtek_smi_remove() is not called when probe() fails.
ds->ops->setup() is called from probe() context. So no double of_node_put().
That's a general rule with the kernel API. When a setup API function fails,
it is responsible of cleaning up the temporary things it did. The
teardown API function is only called when the setup was performed fully.

(the only exception I'm aware of is the Qdisc API, but that's not
exactly the best model to follow)

> If I really needed to put that node in the realtek_smi_remove(), I
> would use a dedicated field in realtek_priv instead of reusing a
> reference for it inside another structure.
> 
> I'll add some notes to the commit message about all these but moving
> the of_node_put() to the same function that gets the node solved all
> the issues.

"Solved all the issues" - what are those issues, first of all?

The simple fact is: of_get_compatible_child() returns an OF node with an
elevated refcount. It passes it to of_mdiobus_register() which does not
take ownership of it per se, but assigns it to bus->dev.of_node, which
is accessible until device_del() from mdiobus_unregister().

The PHY library does not make the ownership rules of the of_node very
clear, but since it takes no reference on it, it will fail in subtle
ways if you pull the carpet from under its feet.

For example, I expect of_mdio_find_bus() to fail. That is used only
rarely, like by the MDIO mux driver which I suppose you haven't tested.

If you want, you could make the OF MDIO API get() and put() the reference,
instead of using something it doesn't fully own. But currently the code
doesn't do that. Try to acknowledge what exists, first.

  reply	other threads:[~2023-12-11 17:11 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08  4:41 [PATCH net-next 0/7] net: dsa: realtek: variants to drivers, interfaces to a common module Luiz Angelo Daros de Luca
2023-12-08  4:41 ` [PATCH net-next 1/7] net: dsa: realtek: drop cleanup from realtek_priv Luiz Angelo Daros de Luca
2023-12-08  9:49   ` Alvin Šipraga
2023-12-08  4:41 ` [PATCH net-next 2/7] net: dsa: realtek: put of node after MDIO registration Luiz Angelo Daros de Luca
2023-12-08  5:13   ` Luiz Angelo Daros de Luca
2023-12-08  9:49     ` Alvin Šipraga
2023-12-08 18:05       ` Luiz Angelo Daros de Luca
2023-12-11 17:11         ` Vladimir Oltean [this message]
2023-12-12  3:47           ` Luiz Angelo Daros de Luca
2023-12-12 21:58             ` Vladimir Oltean
2023-12-13  4:37               ` Luiz Angelo Daros de Luca
2023-12-13 13:04                 ` Vladimir Oltean
2023-12-16  4:26                   ` Luiz Angelo Daros de Luca
2023-12-08  4:41 ` [PATCH net-next 3/7] net: dsa: realtek: convert variants into a real driver Luiz Angelo Daros de Luca
2023-12-08 10:23   ` Alvin Šipraga
2023-12-08  4:41 ` [PATCH net-next 4/7] net: dsa: realtek: create realtek-common Luiz Angelo Daros de Luca
2023-12-08  5:01   ` Luiz Angelo Daros de Luca
2023-12-08 10:52   ` Alvin Šipraga
2023-12-11  5:02     ` Luiz Angelo Daros de Luca
2023-12-11  9:44       ` Alvin Šipraga
2023-12-08 14:02   ` Alvin Šipraga
2023-12-11  5:02     ` Luiz Angelo Daros de Luca
2023-12-11  9:24       ` Alvin Šipraga
2023-12-11 17:19         ` Vladimir Oltean
2023-12-08  4:41 ` [PATCH net-next 5/7] net: dsa: realtek: merge interface modules into common Luiz Angelo Daros de Luca
2023-12-08 10:57   ` Alvin Šipraga
2023-12-11  5:13     ` Luiz Angelo Daros de Luca
2023-12-11  9:25       ` Alvin Šipraga
2023-12-08  4:41 ` [PATCH net-next 6/7] net: dsa: realtek: migrate user_mii setup to common Luiz Angelo Daros de Luca
2023-12-08 11:05   ` Alvin Šipraga
2023-12-11  5:16     ` Luiz Angelo Daros de Luca
2023-12-08  4:41 ` [PATCH net-next 7/7] net: dsa: realtek: always use the realtek user mdio driver Luiz Angelo Daros de Luca
2023-12-08 11:06   ` Alvin Šipraga
2023-12-11  5:29     ` Luiz Angelo Daros de Luca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231211171143.yrvtw7l6wihkbeur@skbuf \
    --to=olteanv@gmail.com \
    --cc=ALSI@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=arinc.unal@arinc9.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox