* [PATCH v2] net: ftgmac100: Hold reference returned by of_get_child_by_name()
@ 2022-07-10 2:07 Liang He
2022-07-12 2:58 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Liang He @ 2022-07-10 2:07 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, windhl, netdev
In ftgmac100_probe(), we should hold the refernece returned by
of_get_child_by_name() and use it to call of_node_put() for
reference balance.
Fixes: 39bfab8844a0 ("net: ftgmac100: Add support for DT phy-handle property")
Signed-off-by: Liang He <windhl@126.com>
---
changelog:
v2: (1) use a helper advised by Jakub (2) add fix tag
v1: directly hold the reference returned by of_get_xx
v1 link: https://lore.kernel.org/all/20220704151819.279513-1-windhl@126.com/
NOTE: I have used an 'inline' to improve the help performance, similar with:
https://lore.kernel.org/all/20181212163548.23723-1-tiny.windzz@gmail.com/
drivers/net/ethernet/faraday/ftgmac100.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 5231818943c6..bcf0767f99fd 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1764,6 +1764,15 @@ static int ftgmac100_setup_clk(struct ftgmac100 *priv)
return rc;
}
+static inline struct device_node *ftgmac100_has_child_node(struct device_node *np, const char *name)
+{
+ struct device_node *child_np = of_get_child_by_name(np, "mdio");
+
+ of_node_put(child_np);
+
+ return child_np;
+}
+
static int ftgmac100_probe(struct platform_device *pdev)
{
struct resource *res;
@@ -1883,7 +1892,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
/* Display what we found */
phy_attached_info(phy);
- } else if (np && !of_get_child_by_name(np, "mdio")) {
+ } else if (np && !ftgmac100_has_child_node(np, "mdio")) {
/* Support legacy ASPEED devicetree descriptions that decribe a
* MAC with an embedded MDIO controller but have no "mdio"
* child node. Automatically scan the MDIO bus for available
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: ftgmac100: Hold reference returned by of_get_child_by_name()
2022-07-10 2:07 [PATCH v2] net: ftgmac100: Hold reference returned by of_get_child_by_name() Liang He
@ 2022-07-12 2:58 ` Jakub Kicinski
2022-07-12 5:51 ` Liang He
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2022-07-12 2:58 UTC (permalink / raw)
To: Liang He; +Cc: davem, edumazet, pabeni, netdev
On Sun, 10 Jul 2022 10:07:28 +0800 Liang He wrote:
> +static inline struct device_node *ftgmac100_has_child_node(struct device_node *np, const char *name)
> +{
> + struct device_node *child_np = of_get_child_by_name(np, "mdio");
> +
> + of_node_put(child_np);
> +
> + return child_np;
Could you make the return type bool ? We don't have a reference on
the child_no node, we should probably not return the pointer.
Also the "inline" keyword is unnecessary the compiler will inline
a small, static function with a single caller, anyway.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:Re: [PATCH v2] net: ftgmac100: Hold reference returned by of_get_child_by_name()
2022-07-12 2:58 ` Jakub Kicinski
@ 2022-07-12 5:51 ` Liang He
0 siblings, 0 replies; 3+ messages in thread
From: Liang He @ 2022-07-12 5:51 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, edumazet, pabeni, netdev
At 2022-07-12 10:58:07, "Jakub Kicinski" <kuba@kernel.org> wrote:
>On Sun, 10 Jul 2022 10:07:28 +0800 Liang He wrote:
>> +static inline struct device_node *ftgmac100_has_child_node(struct device_node *np, const char *name)
>> +{
>> + struct device_node *child_np = of_get_child_by_name(np, "mdio");
>> +
>> + of_node_put(child_np);
>> +
>> + return child_np;
>
>Could you make the return type bool ? We don't have a reference on
>the child_no node, we should probably not return the pointer.
>
>Also the "inline" keyword is unnecessary the compiler will inline
>a small, static function with a single caller, anyway.
Thanks, I will prepare the new version patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-12 5:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-10 2:07 [PATCH v2] net: ftgmac100: Hold reference returned by of_get_child_by_name() Liang He
2022-07-12 2:58 ` Jakub Kicinski
2022-07-12 5:51 ` Liang He
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).