Skip to contentSkip to conversation

net: phy: add missing of_node_put before return

PATCH In review Qing Wang 2 participants 3 messages Dec 13, 2021 – Dec 14, 2021 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 net: phy: add missing of_node_put before return

From: Wang Qing <[email protected]>

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.

---
 drivers/net/phy/mdio_bus.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/mdio_bus.c +1 -0
index 9b6f2df..3c5e8937
@@ -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;
 		}
 	}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Qing Wang

From: Wang Qing <[email protected]>

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.

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

A message that is not in the archive (sent off-list or not yet received): [email protected].@PFliY29jQlpCQUphWjBSZjZAc2hlbGwuYXJtbGludXgub3JnLnVrPg==

author
#3 lore raw
Quoted 19 lines
Quoted 9 lines

From: Wang Qing <[email protected]>

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.

Quoted 8 lines

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

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