linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: phy: add missing of_node_put before return
@ 2021-12-13  9:44 Qing Wang
  2021-12-13 11:03 ` Russell King (Oracle)
       [not found] ` <ALAA5ABiE1JEtj4aLwAwtqpi.9.1639393400698.Hmail.wangqing@vivo.com.@PFliY29jQlpCQUphWjBSZjZAc2hlbGwuYXJtbGludXgub3JnLnVrPg==>
  0 siblings, 2 replies; 3+ messages in thread
From: Qing Wang @ 2021-12-13  9:44 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Jakub Kicinski, netdev, linux-kernel
  Cc: Wang Qing

From: Wang Qing <wangqing@vivo.com>

Fix following coccicheck warning:
WARNING: Function "for_each_available_child_of_node" 
should have of_node_put() before return.

Early exits from for_each_available_child_of_node should decrement the
node reference counter.

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 drivers/net/phy/mdio_bus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 9b6f2df..3c5e8937
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -462,6 +462,7 @@ static void of_mdiobus_link_mdiodev(struct mii_bus *bus,
 
 		if (addr == mdiodev->addr) {
 			device_set_node(dev, of_fwnode_handle(child));
+			of_node_put(child);
 			return;
 		}
 	}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: phy: add missing of_node_put before return
  2021-12-13  9:44 [PATCH] net: phy: add missing of_node_put before return Qing Wang
@ 2021-12-13 11:03 ` Russell King (Oracle)
       [not found] ` <ALAA5ABiE1JEtj4aLwAwtqpi.9.1639393400698.Hmail.wangqing@vivo.com.@PFliY29jQlpCQUphWjBSZjZAc2hlbGwuYXJtbGludXgub3JnLnVrPg==>
  1 sibling, 0 replies; 3+ messages in thread
From: Russell King (Oracle) @ 2021-12-13 11:03 UTC (permalink / raw)
  To: Qing Wang
  Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Jakub Kicinski,
	netdev, linux-kernel

On Mon, Dec 13, 2021 at 01:44:49AM -0800, Qing Wang wrote:
> From: Wang Qing <wangqing@vivo.com>
> 
> Fix following coccicheck warning:
> WARNING: Function "for_each_available_child_of_node" 
> should have of_node_put() before return.
> 
> Early exits from for_each_available_child_of_node should decrement the
> node reference counter.

Most *definitely* NAK. Coccicheck is most definitely wrong on this one,
and we will probably need some way to tell people not to believe
coccicheck on this.

In this path, the DT node is assigned to a struct device. This _must_
be reference counted. device_set_node() does not increment the
reference count, nor does of_fwnode_handle(). The reference count
here is passed from this code over to the struct device.

Adding an of_node_put() will break this.

This must _never_ be "fixed" no matter how much coccicheck complains,
as fixing the warning _will_ introduce a refcounting bug.

I'll send a patch adding a comment to this effect.

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: phy: add missing of_node_put before return
       [not found] ` <ALAA5ABiE1JEtj4aLwAwtqpi.9.1639393400698.Hmail.wangqing@vivo.com.@PFliY29jQlpCQUphWjBSZjZAc2hlbGwuYXJtbGludXgub3JnLnVrPg==>
@ 2021-12-14  2:14   ` 王擎
  0 siblings, 0 replies; 3+ messages in thread
From: 王擎 @ 2021-12-14  2:14 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Jakub Kicinski,
	netdev, linux-kernel


>> From: Wang Qing <wangqing@vivo.com>
>> 
>> Fix following coccicheck warning:
>> WARNING: Function "for_each_available_child_of_node" 
>> should have of_node_put() before return.
>> 
>> Early exits from for_each_available_child_of_node should decrement the
>> node reference counter.
>
>Most *definitely* NAK. Coccicheck is most definitely wrong on this one,
>and we will probably need some way to tell people not to believe
>coccicheck on this.
>
>In this path, the DT node is assigned to a struct device. This _must_
>be reference counted. device_set_node() does not increment the
>reference count, nor does of_fwnode_handle(). The reference count
>here is passed from this code over to the struct device.
>
>Adding an of_node_put() will break this.
>
>This must _never_ be "fixed" no matter how much coccicheck complains,
>as fixing the warning _will_ introduce a refcounting bug.
>
>I'll send a patch adding a comment to this effect.
>
>Thanks.

Yes, you are right. Maybe we can add a judgment in this cocci on which exit as expected 
or abnormally, only the latter needs to be reported.

Thanks,
Qing
>
>-- 
>RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
>FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-14  2:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  9:44 [PATCH] net: phy: add missing of_node_put before return Qing Wang
2021-12-13 11:03 ` Russell King (Oracle)
     [not found] ` <ALAA5ABiE1JEtj4aLwAwtqpi.9.1639393400698.Hmail.wangqing@vivo.com.@PFliY29jQlpCQUphWjBSZjZAc2hlbGwuYXJtbGludXgub3JnLnVrPg==>
2021-12-14  2:14   ` 王擎

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).